siestacat/doctrine-odm-event-listener

Doctrine ODM event listener

1.0.1 2024-01-04 12:26 UTC

This package is auto-updated.

Last update: 2024-05-04 13:12:40 UTC


README

Install:

composer require siestacat/doctrine-odm-event-listener

Add bundle if not auto added:

Siestacat\DoctrineOdmEventListener\DoctrineOdmEventListenerBundle::class => ['all' => true]

Add attribute to your document:


use Siestacat\DoctrineOdmEventListener\EventListenerAttribute;

#[EventListenerAttribute(['App\EventListener\MyDocumentListener'])]

Example of MyDocumentListener:


namespace App\EventListener;

use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
use App\Document\MyDocument;

class MyDocumentListener
{
    public function postPersist(MyDocument $document, LifecycleEventArgs $event) {}
}

List of events:

preRemove
postRemove
prePersist
postPersist
preUpdate
postUpdate
preLoad
postLoad