soyuka / php-to-json-schema
从PHP实体生成JSON模式
1.0.1
2017-01-31 16:19 UTC
Requires
- php: >=7.0
- symfony/property-info: ^3.0
Requires (Dev)
- phpdocumentor/reflection: ^1.0.7
This package is auto-updated.
Last update: 2024-09-19 20:33:38 UTC
README
从PHP实体创建JSON模式。有助于确保给定的JSON文档在对象图中正确反序列化。
安装
使用 https://getcomposer.org.cn 安装库
composer require dunglas/php-to-json-schema
用法
use Dunglas\PhpToJsonSchema\Generator; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\PropertyInfo\PropertyInfoExtractor; class MyClass { private $foo; private $bar; public function setFoo(string $foo) { $this->foo = $foo; } public function setBar(float $bar = null) { $this->bar = $bar; } // ... } $reflectionExtractor = new ReflectionExtractor(); $propertyInfoExtractor = new PropertyInfoExtractor([$reflectionExtractor], [$reflectionExtractor], [], [$reflectionExtractor]); $this->generator = new Generator($propertyInfoExtractor); echo json_encode($generator->generate(MyClass::class));
致谢
由 Kévin Dunglas 创建。