wwwision / types-glossary
1.1.1
2024-08-09 14:57 UTC
Requires
- php: >=8.1
- webmozart/assert: ^1.11
- wwwision/types: ^1.2
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.1
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^4.0.x-dev
README
为 wwwision/types 包提供简单集成,允许生成所有类型的 Markdown 术语表
使用方法
此包可以通过 composer 安装
composer require wwwision/types-glossary
要生成术语表,至少需要一个类
#[StringBased(minLength: 1, maxLength: 200)] final class Name { private function __construct(public readonly string $value) {} } #[IntegerBased(minimum: 1, maximum: 130)] final class Age { private function __construct(public readonly int $value) {} } final class Contact { public function __construct( public readonly Name $name, public readonly Age $age, ) {} } #[ListBased(itemClassName: Contact::class, minCount: 1, maxCount: 5)] final class Contacts { private function __construct(private readonly array $contacts) {} }
现在,可以通过以下方式渲染术语表
// ... $generator = new GlossaryGenerator(); $generator->registerClassNames('Group 01', Name::class, Age::class); $generator->registerClassNames('Group 02', Contact::class, Contacts::class); $expected = <<<MARKDOWN # Group 01 ## Name ### Schema * **type**: string * **minLength**: 1 * **maxLength**: 200 ## Age ### Schema * **type**: integer * **minimum**: 1 * **maximum**: 130 # Group 02 ## Contact ### Schema * **type**: object #### Properties * name ([Name](#name)) * age ([Age](#age)) ## Contacts ### Schema * **type**: array * **items.type**: [Contact](#contact) * **minItems**: 1 * **maxItems**: 5 MARKDOWN; assert($generator->generate() === $expected);
有关更多示例,请参阅 GlossaryGeneratorTest.php
贡献
许可证
请参阅 LICENSE