Skip to content

Commit

Permalink
[Doctrine] Add documentation about doctrine.event_subscriber priority
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse authored and javiereguiluz committed Feb 15, 2021
1 parent 9b334b0 commit fa054e6
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions doctrine/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ with the ``doctrine.event_listener`` tag:
# this is the only required option for the lifecycle listener tag
event: 'postPersist'
# listeners can define their priority in case multiple listeners are associated
# listeners can define their priority in case multiple subscribers or listeners are associated
# to the same event (default priority = 0; higher numbers = listener is run earlier)
priority: 500
Expand All @@ -184,7 +184,7 @@ with the ``doctrine.event_listener`` tag:
<!--
* 'event' is the only required option that defines the lifecycle listener
* 'priority': used when multiple listeners are associated to the same event
* 'priority': used when multiple subscribers or listeners are associated to the same event
* (default priority = 0; higher numbers = listener is run earlier)
* 'connection': restricts the listener to a specific Doctrine connection
-->
Expand Down Expand Up @@ -213,7 +213,7 @@ with the ``doctrine.event_listener`` tag:
// this is the only required option for the lifecycle listener tag
'event' => 'postPersist',
// listeners can define their priority in case multiple listeners are associated
// listeners can define their priority in case multiple subscribers or listeners are associated
// to the same event (default priority = 0; higher numbers = listener is run earlier)
'priority' => 500,
Expand Down Expand Up @@ -428,7 +428,14 @@ with the ``doctrine.event_subscriber`` tag:
App\EventListener\DatabaseActivitySubscriber:
tags:
- { name: 'doctrine.event_subscriber' }
- name: 'doctrine.event_subscriber'
# subscribers can define their priority in case multiple subscribers or listeners are associated
# to the same event (default priority = 0; higher numbers = listener is run earlier)
priority: 500
# you can also restrict listeners to a specific Doctrine connection
connection: 'default'
.. code-block:: xml
Expand All @@ -439,8 +446,15 @@ with the ``doctrine.event_subscriber`` tag:
<services>
<!-- ... -->
<!--
* 'priority': used when multiple subscribers or listeners are associated to the same event
* (default priority = 0; higher numbers = listener is run earlier)
* 'connection': restricts the listener to a specific Doctrine connection
-->
<service id="App\EventListener\DatabaseActivitySubscriber">
<tag name="doctrine.event_subscriber"/>
<tag name="doctrine.event_subscriber" priority="500" connection="default"/>
</service>
</service>
</services>
</container>
Expand All @@ -456,7 +470,14 @@ with the ``doctrine.event_subscriber`` tag:
$services = $configurator->services();
$services->set(DatabaseActivitySubscriber::class)
->tag('doctrine.event_subscriber')
->tag('doctrine.event_subscriber'[
// subscribers can define their priority in case multiple subscribers or listeners are associated
// to the same event (default priority = 0; higher numbers = listener is run earlier)
'priority' => 500,
# you can also restrict listeners to a specific Doctrine connection
'connection' => 'default',
])
;
};
Expand Down Expand Up @@ -505,6 +526,10 @@ can do it in the service configuration:
;
};
.. versionadded:: 5.3

Handling priority for subscribers alongside listeners has been introduced in Symfony 5.3.

.. tip::

Symfony loads (and instantiates) Doctrine subscribers whenever the
Expand Down

0 comments on commit fa054e6

Please sign in to comment.