jworman/annotation-reader
允许解析文档注释中的注释。
1.4.0
2020-08-04 13:23 UTC
Requires
- php: >=5.3
- ext-json: *
Requires (Dev)
- phpstan/phpstan: ^0.12.34
- phpunit/phpunit: ^7.5
README
安装
composer require jworman/annotation-reader
示例
use JWorman\AnnotationReader\AbstractAnnotation; class MyAnnotation extends AbstractAnnotation { }
use MyAnnotation; class Example { /** * @MyAnnotation("fizzbuzz") */ private $id; }
use JWorman\AnnotationReader\AnnotationReader; $annotationReader = new AnnotationReader(); $reflectionProperty = new \ReflectionProperty('Example', 'id'); $annotation = $annotationReader->getPropertyAnnotation($reflectionProperty, 'MyAnnotation'); $value = $annotation->getValue(); // Returns "fizzbuzz"
注释可以包含任何有效的JSON值。
/** * @MyAnnotation("fizzbuzz") * @AnotherOne({"isCool": true, "list": [null, false, {"nested": "object"}]}) */
在其JSON中定义对象的注释将具有从JSON映射到其属性的属性。
use JWorman\AnnotationReader\AbstractAnnotation; class AnotherOne extends AbstractAnnotation { private $isCool; // From above annotations will equal: true private $list; // From above annotations will equal: [null, false, \stdObject()] }