kenny1911/doctrine-inherit-annotations

Support inherit doctrine annotations of parent class

v1.0.0 2021-02-24 07:02 UTC

This package is auto-updated.

Last update: 2025-04-24 16:22:39 UTC


README

InheritAnnotationReader - is implementation of Reader interface from doctrine/annotations package, that support inherit annotations from parent class. To do this, you must specify @Kenny1911\DoctrineInheritAnnotations\Annotation\Inherit annotation, like as @inheritDoc from PHPDoc.

New InheritAnnotationReader instance

InheritAnnotationReader instance is decorate original Reader:

use Doctrine\Common\Annotations\AnnotationReader;
use Kenny1911\DoctrineInheritAnnotations\InheritAnnotationReader;

$reader = new AnnotationReader(); // Original annotation reader

$inheritReader = new InheritAnnotationReader($reader);

Usage

use Doctrine\Common\Annotations\AnnotationReader;
use Kenny1911\DoctrineInheritAnnotations\Annotation\Inherit;
use Kenny1911\DoctrineInheritAnnotations\InheritAnnotationReader;

/**
 * @FooAnnotation()
 */
class ParentClass {}

/**
 * @BarAnnotation()
 * 
 * @Inherit()
 */
class ChildClass extends ParentClass {}

$reader = new AnnotationReader();
$reader->getClassAnnotations(new ReflectionClass(ChildClass::class)); // return [@BarAnnotation(), @Inherit()]

$inheritReader = new InheritAnnotationReader($reader);
$inheritReader->getClassAnnotations(new ReflectionClass(ChildClass::class)); // return [@BarAnnotation(), @Inherit(), @FooAnnotation()]