jworman / annotation-reader
Allows the parsing of annotations within doc comments.
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
Install:
composer require jworman/annotation-reader
Example:
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"
Annotations can have any valid JSON value inside them.
/** * @MyAnnotation("fizzbuzz") * @AnotherOne({"isCool": true, "list": [null, false, {"nested": "object"}]}) */
Annotations that define objects in their JSON will have their properties mapped to from the 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()] }