fmasa / doctrine-yaml-annotations
Custom annotations for YAML mapping
Installs: 1 954
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- doctrine/orm: ^2.5
- symfony/yaml: ^3.2
Requires (Dev)
- phpunit/phpcov: ^4.0
- phpunit/phpunit: ^6.0
- satooshi/php-coveralls: ^1.0
This package is auto-updated.
Last update: 2023-09-16 21:24:13 UTC
README
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:
$ composer require fmasa/doctrine-yaml-annotations
For example let's configure the Consistence extension for Doctrine.
First we have to create annotation reader:
use Fmasa\DoctrineYamlAnnotations\YamlReader; $configuration = $entityManager->getConfiguration(); $reader = new YamlReader($configuration, [ 'enum' => EnumAnnotation::class ]);
Second argument for AnnotationReader is optional map with entity aliases.
Add annotations to your mapping files:
Some\Entity: ... fields: state: type: enum_string annotations: Consistence\Doctrine\Enum\EnumAnnotation: # or just enum class: StateEnum
Now you can read annotations just using Doctrine\Common\Annotations\Reader
API:
$reader->getPropertyAnnotation( (new \ReflectionClass(Some\Entity::class))->getProperty('state'), EnumAnnotation::class ); // returns instance of EnumAnnotation { class => "StateEnum" }