Skip to content

Commit 5e84b6c

Browse files
authored
[Doctrine Bridge] document priority for doctrine.event_listener tag
Fixes #7649
1 parent fb039a7 commit 5e84b6c

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
@@ -270,3 +270,55 @@ to the tag like so:
270270

271271
.. _`The Event System`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
272272
.. _`the Doctrine Documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#entity-listeners
273+
274+
275+
Priorities for Event Listeners
276+
--------------------------------
277+
278+
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.
279+
280+
.. configuration-block::
281+
282+
.. code-block:: yaml
283+
284+
services:
285+
my.listener.with_high_priority:
286+
class: AppBundle\EventListener\MyHighPriorityListener
287+
tags:
288+
- { name: doctrine.event_listener, event: postPersist, priority: 10 }
289+
290+
my.listener.with_low_priority:
291+
class: AppBundle\EventListener\MyLowPriorityListener
292+
tags:
293+
- { name: doctrine.event_listener, event: postPersist, priority: 1 }
294+
295+
.. code-block:: xml
296+
297+
<?xml version="1.0" ?>
298+
<container xmlns="http://symfony.com/schema/dic/services"
299+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
300+
301+
<services>
302+
<service id="my.listener.with_high_priority" class="AppBundle\EventListener\MyHighPriorityListener">
303+
<tag name="doctrine.event_listener" event="postPersist" priority="10" />
304+
</service>
305+
<service id="my.listener.with_low_priority" class="AppBundle\EventListener\MyLowPriorityListener">
306+
<tag name="doctrine.event_listener" event="postPersist" priority="1" />
307+
</service>
308+
</services>
309+
</container>
310+
311+
.. code-block:: php
312+
313+
use AppBundle\EventListener\MyHighPriorityListener;
314+
use AppBundle\EventListener\MyLowPriorityListener;
315+
316+
$container
317+
->register('my.listener.with_high_priority', MyHighPriorityListener::class)
318+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 10))
319+
;
320+
321+
$container
322+
->register('my.listener.with_low_priority', MyLowPriorityListener::class)
323+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 1))
324+
;

0 commit comments

Comments
 (0)