@@ -242,3 +242,56 @@ to the tag like so:
242242
243243.. _`The Event System` : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
244244.. _`the Doctrine Documentation` : https://symfony.com/doc/current/bundles/DoctrineBundle/entity-listeners.html
245+
246+ Priorities for Event Listeners
247+ ------------------------------
248+
249+ In case you have multiple listeners for the same event you can control the order
250+ in which they are invoked using the ``priority `` attribute on the tag.
251+ Listeners with a higher priority are invoked first.
252+
253+ .. configuration-block ::
254+
255+ .. code-block :: yaml
256+
257+ services :
258+ my.listener.with_high_priority :
259+ class : AppBundle\EventListener\MyHighPriorityListener
260+ tags :
261+ - { name: doctrine.event_listener, event: postPersist, priority: 10 }
262+
263+ my.listener.with_low_priority :
264+ class : AppBundle\EventListener\MyLowPriorityListener
265+ tags :
266+ - { name: doctrine.event_listener, event: postPersist, priority: 1 }
267+
268+ .. code-block :: xml
269+
270+ <?xml version =" 1.0" ?>
271+ <container xmlns =" http://symfony.com/schema/dic/services"
272+ xmlns : doctrine =" http://symfony.com/schema/dic/doctrine" >
273+
274+ <services >
275+ <service id =" my.listener.with_high_priority" class =" AppBundle\EventListener\MyHighPriorityListener" >
276+ <tag name =" doctrine.event_listener" event =" postPersist" priority =" 10" />
277+ </service >
278+ <service id =" my.listener.with_low_priority" class =" AppBundle\EventListener\MyLowPriorityListener" >
279+ <tag name =" doctrine.event_listener" event =" postPersist" priority =" 1" />
280+ </service >
281+ </services >
282+ </container >
283+
284+ .. code-block :: php
285+
286+ use AppBundle\EventListener\MyHighPriorityListener;
287+ use AppBundle\EventListener\MyLowPriorityListener;
288+
289+ $container
290+ ->register('my.listener.with_high_priority', MyHighPriorityListener::class)
291+ ->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 10))
292+ ;
293+
294+ $container
295+ ->register('my.listener.with_low_priority', MyLowPriorityListener::class)
296+ ->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 1))
297+ ;
0 commit comments