@@ -270,3 +270,55 @@ to the tag like so:
270
270
271
271
.. _`The Event System` : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
272
272
.. _`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