diff --git a/Resources/doc/events.rst b/Resources/doc/events.rst index 492cc7bc..2fce600a 100644 --- a/Resources/doc/events.rst +++ b/Resources/doc/events.rst @@ -11,10 +11,25 @@ see Doctrine's `Event Documentation`_. document managers tied to that connection. Listeners and subscribers may be registered with all event managers or just one (using the connection name). -To register a service to act as an event listener you have to tag it with the -``doctrine_mongodb.odm.event_listener`` tag. +Use the ``doctrine_mongodb.odm.event_listener`` tag to register a listener. The +``event`` attribute is required and should denote the event on which to listen. +By default, listeners will be registered with event managers for all connections. +To restrict a listener to a single connection, specify its name in the tag's +``connection`` attribute. -Starting with Doctrine bundle 2.8, you can use the ``AsDocumentListener`` attribute to tag the service. + +The ``priority`` attribute, which defaults to ``0`` if omitted, may be used +to control the order in which listeners are registered. Much like Symfony's +`event dispatcher`_, greater number will result in the listener executing +first and listeners with the same priority will be executed in the order that +they were registered with the event manager. + +Lastly, the ``lazy`` attribute, which defaults to ``false`` if omitted, may +be used to request that the listener be lazily loaded by the event manager +when its event is dispatched. + +Starting with Doctrine bundle 2.8, you can use the ``#[AsDocumentListener]`` +attribute to tag the service. .. configuration-block:: @@ -24,7 +39,7 @@ Starting with Doctrine bundle 2.8, you can use the ``AsDocumentListener`` attrib namespace App\EventListener; use Doctrine\Bundle\MongoDBBundle\Attribute\AsDocumentListener; - use Doctrine\ORM\Event\LifecycleEventArgs; + use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs; #[AsDocumentListener('postPersist', priority: 500, connection: 'default')] class SearchIndexer @@ -71,7 +86,7 @@ Starting with Doctrine bundle 2.8, you can use the ``AsDocumentListener`` attrib * 'connection': restricts the listener to a specific MongoDB connection --> - @@ -86,4 +101,5 @@ Starting with Doctrine bundle 2.8, you can use the ``AsDocumentListener`` attrib event(s). For this reason, the aforementioned tags have no ``method`` attribute. +.. _`event dispatcher`: https://symfony.com/doc/current/components/event_dispatcher.html .. _`Event Documentation`: https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/events.html