项目作者: fmasa

项目描述 :
Support for custom Doctrine annotations in yaml
高级语言: PHP
项目地址: git://github.com/fmasa/doctrine-yaml-annotations.git
创建时间: 2017-04-02T07:58:43Z
项目社区:https://github.com/fmasa/doctrine-yaml-annotations

开源协议:MIT License

下载


Doctrine YAML annotations

Build Status
Coverage Status

One of the great features of Doctrine 2 is extensibility.
Doctrine offers multiple ways to specify mapping information,
but the most of the extensions only supports Annotations configuration.

This package adds custom annotations to your YAML mapping files.

What is currently supported:

  • property annotations (fields and embeddables)
  • class annotations

Installation

The best way to install fmasa/doctrine-yaml-annotations is using Composer:

  1. $ composer require fmasa/doctrine-yaml-annotations

For example let’s configure the Consistence extension for Doctrine.

First we have to create annotation reader:

  1. use Fmasa\DoctrineYamlAnnotations\YamlReader;
  2. $configuration = $entityManager->getConfiguration();
  3. $reader = new YamlReader($configuration, [
  4. 'enum' => EnumAnnotation::class
  5. ]);

Second argument for AnnotationReader is optional map with entity aliases.

Add annotations to your mapping files:

  1. Some\Entity:
  2. ...
  3. fields:
  4. state:
  5. type: enum_string
  6. annotations:
  7. Consistence\Doctrine\Enum\EnumAnnotation: # or just enum
  8. class: StateEnum

Now you can read annotations just using Doctrine\Common\Annotations\Reader API:

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