doctrine / phpcr-odm

Doctrine PHPCR ODM
http://www.doctrine-project.org/projects/phpcr-odm.html
MIT License
183 stars 96 forks source link

DocumentListeners #531

Open asiragusa opened 10 years ago

asiragusa commented 10 years ago

Doctrine ORM allows to define listeners for specific Entities (http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#entity-listeners). Is it possible to do the same thing with PHPCR-ODM?

dantleech commented 10 years ago

No this isn't implemented (afaik), but would be a valid feature. So you could make a PR or change this to a feature request.

In the meantime you can always use normal event listeners and do something like:

class FoobarEventListener
{
    public function preUpdate(PreUpdateEvent $event)
    {
        $document = $event->getObject();

        if ($document instanceof MyProject\Document\User) {
          // do something
        } 
}
asiragusa commented 10 years ago

Yep, it's what I was thinking to do.

When I will have some spare time I will work on this feature.

dbu commented 10 years ago

sounds great! phpcr-odm was started looking at the code of the orm around 2.1 i think, and we have not ported over all the features. some things move into doctrine commons, which help a lot as it allows to share code instead of reimplementing - but when things get too specific, that is not an option. @ocramius was doing a lot of the pushing to commons, maybe he has some input on this one?

Ocramius commented 10 years ago

This is something that has been completely designed/implemented by @FabioBatSilva, so better check it with him :-)

The logic was strictly coupled with the UoW IIRC