fmasa/doctrine-yaml-annotations

此包已被废弃,不再维护。未建议替代包。

YAML映射的自定义注解

1.1.0 2018-02-03 15:02 UTC

This package is auto-updated.

Last update: 2023-09-16 21:24:13 UTC


README

Build Status Coverage Status

Doctrine 2的一个伟大特性是其可扩展性。Doctrine提供了多种指定映射信息的方式,但大多数扩展仅支持注解配置。

此包为您的YAML映射文件添加自定义注解。

当前支持的内容

  • 属性注解(字段和嵌入对象)
  • 类注解

安装

安装fmasa/doctrine-yaml-annotations的最佳方式是使用Composer

$ composer require fmasa/doctrine-yaml-annotations

例如,让我们为Doctrine配置Consistence扩展。

首先,我们需要创建注解读取器

use Fmasa\DoctrineYamlAnnotations\YamlReader;

$configuration = $entityManager->getConfiguration();
$reader = new YamlReader($configuration, [
    'enum' => EnumAnnotation::class
]);
    

AnnotationReader的第二个参数是一个可选的映射,包含实体别名。

将注解添加到您的映射文件中

Some\Entity:
    
    ...
    
    fields:
        state:
            type: enum_string
            annotations:
                Consistence\Doctrine\Enum\EnumAnnotation: # or just enum
                    class: StateEnum

现在您可以使用Doctrine\Common\Annotations\Reader API读取注解

$reader->getPropertyAnnotation(
    (new \ReflectionClass(Some\Entity::class))->getProperty('state'),
    EnumAnnotation::class
); // returns instance of EnumAnnotation { class => "StateEnum" }