jworman / annotation-reader
Allows the parsing of annotations within doc comments.
Installs: 716
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/jworman/annotation-reader
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()] }