From 5888386a89b2484e6129e230c6ab60d40fe26fa1 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Wed, 20 Jun 2018 22:39:11 +0200 Subject: [PATCH 1/2] [Doctrine Bridge] document priority for doctrine.event_listener tag Fixes https://github.com/symfony/symfony-docs/issues/7649 --- doctrine/event_listeners_subscribers.rst | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/doctrine/event_listeners_subscribers.rst b/doctrine/event_listeners_subscribers.rst index 3d12dc253b1..b706e95c97b 100644 --- a/doctrine/event_listeners_subscribers.rst +++ b/doctrine/event_listeners_subscribers.rst @@ -271,3 +271,55 @@ to the tag like so: .. _`The Event System`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html .. _`the Doctrine Documentation`: https://symfony.com/doc/current/bundles/DoctrineBundle/entity-listeners.html + + +Priorities for Event Listeners +-------------------------------- + +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. + +.. configuration-block:: + + .. code-block:: yaml + + services: + my.listener.with_high_priority: + class: AppBundle\EventListener\MyHighPriorityListener + tags: + - { name: doctrine.event_listener, event: postPersist, priority: 10 } + + my.listener.with_low_priority: + class: AppBundle\EventListener\MyLowPriorityListener + tags: + - { name: doctrine.event_listener, event: postPersist, priority: 1 } + + .. code-block:: xml + + + + + + + + + + + + + + + .. code-block:: php + + use AppBundle\EventListener\MyHighPriorityListener; + use AppBundle\EventListener\MyLowPriorityListener; + + $container + ->register('my.listener.with_high_priority', MyHighPriorityListener::class) + ->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 10)) + ; + + $container + ->register('my.listener.with_low_priority', MyLowPriorityListener::class) + ->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 1)) + ; From 472114bb774dac7b82d620b56c398f0f37061fbf Mon Sep 17 00:00:00 2001 From: David Maicher Date: Tue, 4 Sep 2018 20:54:56 +0200 Subject: [PATCH 2/2] review feedback --- doctrine/event_listeners_subscribers.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doctrine/event_listeners_subscribers.rst b/doctrine/event_listeners_subscribers.rst index b706e95c97b..324f8519292 100644 --- a/doctrine/event_listeners_subscribers.rst +++ b/doctrine/event_listeners_subscribers.rst @@ -274,9 +274,11 @@ to the tag like so: Priorities for Event Listeners --------------------------------- +------------------------------ -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. +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. .. configuration-block::