phpcr-odm icon indicating copy to clipboard operation
phpcr-odm copied to clipboard

DocumentListeners

Open asiragusa opened this issue 10 years ago • 4 comments

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?

asiragusa avatar Jul 27 '14 11:07 asiragusa

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
        } 
}

dantleech avatar Jul 27 '14 11:07 dantleech

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

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

asiragusa avatar Jul 27 '14 11:07 asiragusa

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?

dbu avatar Jul 28 '14 06:07 dbu

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

Ocramius avatar Jul 28 '14 10:07 Ocramius