Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 582
Matt Avatar asked Nov 28 '11 15:11

Matt


People also ask

What is Symfony used for?

Symfony is a feature-rich back-end framework that is used to build complex applications. Many developers still prefer the lightweight Silex micro-framework or the Symfony MicroKernel, and Symfony is a widely used application framework among open-source developers.

What is Symphony software?

Symfony is an open-source PHP web application framework, designed for developers who need a simple and elegant toolkit to create full-featured web applications. Symfony is sponsored by SensioLabs. It was developed by Fabien Potencier in 2005.

Which is better Laravel or Symfony?

Both PHP Laravel and Symfony PHP are developed on MVC architecture, but in terms of component reusability and code modularity, Symfony has the edge over Laravel on this one.

Who created Symfony?

Fabien Potencier Being a developer by passion, he immediately started to build websites with Perl. But with the release of PHP 5, he decided to switch focus to PHP, and created the symfony framework project in 2004 to help his company leverage the power of PHP for its customers.


1 Answers

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.

like image 124
Herzult Avatar answered Oct 07 '22 04:10

Herzult