8000 minor #9944 [Doctrine Bridge] document priority for doctrine.event_li… · symfony/symfony-docs@9663621 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9663621

Browse files
committed
minor #9944 [Doctrine Bridge] document priority for doctrine.event_listener tag (dmaicher)
This PR was squashed before being merged into the 2.8 branch (closes #9944). Discussion ---------- [Doctrine Bridge] document priority for doctrine.event_listener tag Fixes #7649 Commits ------- ed986b2 [Doctrine Bridge] document priority for doctrine.event_listener tag
2 parents dc1c452 + ed986b2 commit 9663621

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

doctrine/event_listeners_subscribers.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,57 @@ 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
280+
in which they are invoked using the ``priority`` attribute on the tag.
281+
Listeners with a higher priority are invoked first.
282+
283+
.. configuration-block::
284+
285+
.. code-block:: yaml
286+
287+
services:
288+
my.listener.with_high_priority:
289+
class: AppBundle\EventListener\MyHighPriorityListener
290+
tags:
291+
- { name: doctrine.event_listener, event: postPersist, priority: 10 }
292+
293+
my.listener.with_low_priority:
294+
class: AppBundle\EventListener\MyLowPriorityListener
295+
tags:
296+
- { name: doctrine.event_listener, event: postPersist, priority: 1 }
297+
298+
.. code-block:: xml
299+
300+
<?xml version="1.0" ?>
301+
<container xmlns="http://symfony.com/schema/dic/services"
302+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
303+
304+
<services>
305+
<service id="my.listener.with_high_priority" class="AppBundle\EventListener\MyHighPriorityListener">
306+
<tag name="doctrine.event_listener" event="postPersist" priority="10" />
307+
</service>
308+
<service id="my.listener.with_low_priority" class="AppBundle\EventListener\MyLowPriorityListener">
309+
<tag name="doctrine.event_listener" event="postPersist" priority="1" />
310+
</service>
311+
</services>
312+
</container>
313+
314+
.. code-block:: php
315+
316+
use AppBundle\EventListener\MyHighPriorityListener;
317+
use AppBundle\EventListener\MyLowPriorityListener;
318+
319+
$container
320+
->register('my.listener.with_high_priority', MyHighPriorityListener::class)
321+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 10))
322+
;
323+
324+
$container
325+
->register('my.listener.with_low_priority', MyLowPriorityListener::class)
326+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 1))
327+
;

0 commit comments

Comments
 (0)
0