jworman/annotation-reader

Allows the parsing of annotations within doc comments.

1.4.0 2020-08-04 13:23 UTC

This package is auto-updated.

Last update: 2025-03-01 00:32:10 UTC


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()]
}