kenny1911/doctrine-inherit-annotations

支持继承父类的 doctrine 注解

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

This package is auto-updated.

Last update: 2024-09-24 15:09:17 UTC


README

InheritAnnotationReader - 是从 doctrine/annotations 包实现的 Reader 接口,支持从父类继承注解。为此,您必须指定 @Kenny1911\DoctrineInheritAnnotations\Annotation\Inherit 注解,类似于从 PHPDoc 中的 @inheritDoc

创建新的 InheritAnnotationReader 实例

InheritAnnotationReader 实例装饰了原始的 Reader

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

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

$inheritReader = new InheritAnnotationReader($reader);

用法

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