6

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

1
  • Underlying question : are you supposed to integrate this in a bundle or are there pieces of code that you can put elsewhere? If you look at the README of the doctrine extensions bundle, you'll see that this bundle is dependant on a library that will go inside lib/vendor, and that is not a bundle. Commented Nov 28, 2011 at 19:34

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.