PHP code example of lvyun66 / json2php
1. Go to this page and download the library: Download lvyun66/json2php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lvyun66 / json2php example snippets
$namespace = 'tests\\output\\general';
$output = TEST_ROOT . '/output/general/';
if (!is_dir($output)) {
mkdir($output);
}
$g = new GeneratorPhpFile();
$jsonPath = TEST_ROOT . '/json/normal.json';
$g->generator(file_get_contents($jsonPath), 'Normal', $namespace, $output);
$namespace = 'tests\\output\\yii2';
$output = TEST_ROOT . '/output/yii2/';
if (!is_dir($output)) {
mkdir($output);
}
$g = new GeneratorYiiModel();
$jsonPath = TEST_ROOT . '/json/normal.json';
$g->generator(file_get_contents($jsonPath), 'Normal', $namespace, $output);
/**
* Code generated by json2php. DO NOT EDIT.
* Generator at 2018-09-06 04:15:27
*/
namespace test\lvyun;
class UserInfo
{
/** @var string */
private $name;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param $name string
*/
public function setName($name)
{
$this->name = $name;
}
}