alexnguetcha / json-to-class
此包最新版本(dev-master)没有提供许可证信息。
从json文件创建php类的简单工具。
dev-master
2020-09-20 19:21 UTC
This package is auto-updated.
Last update: 2024-09-21 04:07:49 UTC
README
简单工具,用于从 json文件 创建 php类。
示例
{ "class_name": "post", "class_attrs": { "id": { "type": "int", "visibility": "private" }, "id_member": { "type": "int", "visibility": "private" }, "content": { "type": "string", "visibility": "private" }, "create_at": { "type": "DateTime", "visibility": "private" } } }
$jtc = new JsonToClass(__DIR__."\\post.json"); $jtc->toFile();
输出
//Post.php <?php class Person { private $name; private $old; private $sick; public function __construct(string $name, int $old, bool $sick) { $this->name = $name; $this->old = $old; $this->sick = $sick; } public function getName(): string { return $this->name; } public function getOld(): int { return $this->old; } public function isSick(): bool { return $this->sick; } public function setName(string $name):self { $this->name = $name; return $this; } public function setOld(int $old):self { $this->old = $old; return $this; } public function setSick(bool $sick):self { $this->sick = $sick; return $this; } }