@@ -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