Skip to content

Commit 5888386

Browse files
committed
[Doctrine Bridge] document priority for doctrine.event_listener tag
Fixes #7649
1 parent e2050c5 commit 5888386

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

doctrine/event_listeners_subscribers.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,55 @@ to the tag like so:
271271

272272
.. _`The Event System`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
273273
.. _`the Doctrine Documentation`: https://symfony.com/doc/current/bundles/DoctrineBundle/entity-listeners.html
274+
275+
276+
Priorities for Event Listeners
277+
--------------------------------
278+
279+
In case you have multiple listeners for the same event you can control the order in which they are invoked using the `priority` attribute on the tag. Listeners with a higher priority are invoked first.
280+
281+
.. configuration-block::
282+
283+
.. code-block:: yaml
284+
285+
services:
286+
my.listener.with_high_priority:
287+
class: AppBundle\EventListener\MyHighPriorityListener
288+
tags:
289+
- { name: doctrine.event_listener, event: postPersist, priority: 10 }
290+
291+
my.listener.with_low_priority:
292+
class: AppBundle\EventListener\MyLowPriorityListener
293+
tags:
294+
- { name: doctrine.event_listener, event: postPersist, priority: 1 }
295+
296+
.. code-block:: xml
297+
298+
<?xml version="1.0" ?>
299+
<container xmlns="http://symfony.com/schema/dic/services"
300+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
301+
302+
<services>
303+
<service id="my.listener.with_high_priority" class="AppBundle\EventListener\MyHighPriorityListener">
304+
<tag name="doctrine.event_listener" event="postPersist" priority="10" />
305+
</service>
306+
<service id="my.listener.with_low_priority" class="AppBundle\EventListener\MyLowPriorityListener">
307+
<tag name="doctrine.event_listener" event="postPersist" priority="1" />
308+
</service>
309+
</services>
310+
</container>
311+
312+
.. code-block:: php
313+
314+
use AppBundle\EventListener\MyHighPriorityListener;
315+
use AppBundle\EventListener\MyLowPriorityListener;
316+
317+
$container
318+
->register('my.listener.with_high_priority', MyHighPriorityListener::class)
319+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 10))
320+
;
321+
322+
$container
323+
->register('my.listener.with_low_priority', MyLowPriorityListener::class)
324+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 1))
325+
;

0 commit comments

Comments
 (0)