| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | Deprecation notice==================PHP 8 introduced `attributes<https://www.php.net/manual/en/language.attributes.overview.php>`_,which are a native replacement for annotations. As such, this library isconsidered feature complete, and should receive exclusively bugfixes andsecurity fixes.Introduction============Doctrine Annotations allows to implement custom annotationfunctionality for PHP classes and functions... code-block:: php    class Foo    {        /**         * @MyAnnotation(myProperty="value")         */        private $bar;    }Annotations aren't implemented in PHP itself which is why this componentoffers a way to use the PHP doc-blocks as a place for the well knownannotation syntax using the ``@`` char.Annotations in Doctrine are used for the ORM configuration to build theclass mapping, but it can be used in other projects for other purposestoo.Installation============You can install the Annotation component with composer:.. code-block::    $ composer require doctrine/annotationsCreate an annotation class==========================An annotation class is a representation of the later used annotationconfiguration in classes. The annotation class of the previous examplelooks like this:.. code-block:: php    /**     * @Annotation     */    final class MyAnnotation    {        public $myProperty;    }The annotation class is declared as an annotation by ``@Annotation``.:ref:`Read more about custom annotations. <custom>`Reading annotations===================The access to the annotations happens by reflection of the class or functioncontaining them. There are multiple reader-classes implementing the``Doctrine\Common\Annotations\Reader`` interface, that can access theannotations of a class. A common one is``Doctrine\Common\Annotations\AnnotationReader``:.. code-block:: php    use Doctrine\Common\Annotations\AnnotationReader;    use Doctrine\Common\Annotations\AnnotationRegistry;    // Deprecated and will be removed in 2.0 but currently needed    AnnotationRegistry::registerLoader('class_exists');    $reflectionClass = new ReflectionClass(Foo::class);    $property = $reflectionClass->getProperty('bar');    $reader = new AnnotationReader();    $myAnnotation = $reader->getPropertyAnnotation(        $property,        MyAnnotation::class    );    echo $myAnnotation->myProperty; // result: "value"Note that ``AnnotationRegistry::registerLoader('class_exists')`` only worksif you already have an autoloader configured (i.e. composer autoloader).Otherwise, :ref:`please take a look to the other annotation autoload mechanisms <annotations>`.A reader has multiple methods to access the annotations of a class orfunction.:ref:`Read more about handling annotations. <annotations>`IDE Support-----------Some IDEs already provide support for annotations:- Eclipse via the `Symfony2 Plugin <https://github.com/pulse00/Symfony-2-Eclipse-Plugin>`_- PhpStorm via the `PHP Annotations Plugin <https://plugins.jetbrains.com/plugin/7320-php-annotations>`_ or the `Symfony Plugin <https://plugins.jetbrains.com/plugin/7219-symfony-support>`_.. _Read more about handling annotations.: annotations.. _Read more about custom annotations.: custom
 |