dunglas / php-to-json-schema
v0.1.0
2016-01-11 15:45 UTC
Requires
- php: >=7.0
- symfony/property-info: ~2.8|~3.0
Requires (Dev)
- phpdocumentor/reflection: ^1.0.7
This package is auto-updated.
Last update: 2022-01-10 20:44:46 UTC
README
此库已弃用,请使用 API Platform JSON Schema 代替。
从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]); $generator = new Generator($propertyInfoExtractor); echo json_encode($generator->generate(MyClass::class));
致谢
由 Kévin Dunglas 创建。