简体   繁体   中英

Symfony2 & Doctrine2 : Create custom annotations

I'd like to create a few custom annotations for an Entity class, i've come across this article on Doctrine2 however i'm unsure as to how to integrate this into my Symfony bundle, can anybody shed some light on this?

class User implements UserInterface
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @myCustomVar(remember="true")
     */
    protected $id;

Thanks

Inspire you to the doctrine extension:

  • The DoctrineExtensions library contains some annotation classes. But as this annotations does not mean anything for the Doctrine core, it's also this extension that is responsible of interpreting them. To do that, it uses some listeners that must be registered into the Doctrine's event dispatcher.

  • In Symfony you can declare services with the doctrine.event_listener (or doctrine.event_subscriber for event subscribers) so the Doctrine bundle will find them and register them for you. The StofDoctrineExtensionsBundle primarily aims to automate this part of event listeners registration.

Anyway, when you think about extending Doctrine, as it can be used without Symfony, prefer to divide your work in two parts: one is the doctrine extension, the other is the glue between this extension and Symfony and is called bundle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM