Skip to content

Commit

Permalink
doc review
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Dec 22, 2023
1 parent 5149dfd commit 9a008ee
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Resources/doc/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 DoctrineMongoDBBundle bundle 4.7, you can use the ``#[AsDocumentListener]``
attribute to tag the service.

.. configuration-block::

Expand All @@ -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
Expand Down Expand Up @@ -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
-->
<service id="App\EventListener\SearchIndexer">
<tag name="doctrine.event_listener"
<tag name="doctrine_mongodb.odm.event_listener"
event="postPersist"
priority="500"
connection="default" />
Expand All @@ -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

0 comments on commit 9a008ee

Please sign in to comment.