Skip to content

Commit fa054e6

Browse files
jderussejaviereguiluz
authored andcommitted
[Doctrine] Add documentation about doctrine.event_subscriber priority
1 parent 9b334b0 commit fa054e6

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

doctrine/events.rst

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ with the ``doctrine.event_listener`` tag:
166166
# this is the only required option for the lifecycle listener tag
167167
event: 'postPersist'
168168
169-
# listeners can define their priority in case multiple listeners are associated
169+
# listeners can define their priority in case multiple subscribers or listeners are associated
170170
# to the same event (default priority = 0; higher numbers = listener is run earlier)
171171
priority: 500
172172
@@ -184,7 +184,7 @@ with the ``doctrine.event_listener`` tag:
184184
185185
<!--
186186
* 'event' is the only required option that defines the lifecycle listener
187-
* 'priority': used when multiple listeners are associated to the same event
187+
* 'priority': used when multiple subscribers or listeners are associated to the same event
188188
* (default priority = 0; higher numbers = listener is run earlier)
189189
* 'connection': restricts the listener to a specific Doctrine connection
190190
-->
@@ -213,7 +213,7 @@ with the ``doctrine.event_listener`` tag:
213213
// this is the only required option for the lifecycle listener tag
214214
'event' => 'postPersist',
215215
216-
// listeners can define their priority in case multiple listeners are associated
216+
// listeners can define their priority in case multiple subscribers or listeners are associated
217217
// to the same event (default priority = 0; higher numbers = listener is run earlier)
218218
'priority' => 500,
219219
@@ -428,7 +428,14 @@ with the ``doctrine.event_subscriber`` tag:
428428
429429
App\EventListener\DatabaseActivitySubscriber:
430430
tags:
431-
- { name: 'doctrine.event_subscriber' }
431+
- name: 'doctrine.event_subscriber'
432+
433+
# subscribers can define their priority in case multiple subscribers or listeners are associated
434+
# to the same event (default priority = 0; higher numbers = listener is run earlier)
435+
priority: 500
436+
437+
# you can also restrict listeners to a specific Doctrine connection
438+
connection: 'default'
432439
433440
.. code-block:: xml
434441
@@ -439,8 +446,15 @@ with the ``doctrine.event_subscriber`` tag:
439446
<services>
440447
<!-- ... -->
441448
449+
<!--
450+
* 'priority': used when multiple subscribers or listeners are associated to the same event
451+
* (default priority = 0; higher numbers = listener is run earlier)
452+
* 'connection': restricts the listener to a specific Doctrine connection
453+
-->
442454
<service id="App\EventListener\DatabaseActivitySubscriber">
443-
<tag name="doctrine.event_subscriber"/>
455+
<tag name="doctrine.event_subscriber" priority="500" connection="default"/>
456+
</service>
457+
444458
</service>
445459
</services>
446460
</container>
@@ -456,7 +470,14 @@ with the ``doctrine.event_subscriber`` tag:
456470
$services = $configurator->services();
457471
458472
$services->set(DatabaseActivitySubscriber::class)
459-
->tag('doctrine.event_subscriber')
473+
->tag('doctrine.event_subscriber'[
474+
// subscribers can define their priority in case multiple subscribers or listeners are associated
475+
// to the same event (default priority = 0; higher numbers = listener is run earlier)
476+
'priority' => 500,
477+
478+
# you can also restrict listeners to a specific Doctrine connection
479+
'connection' => 'default',
480+
])
460481
;
461482
};
462483
@@ -505,6 +526,10 @@ can do it in the service configuration:
505526
;
506527
};
507528
529+
.. versionadded:: 5.3
530+
531+
Handling priority for subscribers alongside listeners has been introduced in Symfony 5.3.
532+
508533
.. tip::
509534

510535
Symfony loads (and instantiates) Doctrine subscribers whenever the

0 commit comments

Comments
 (0)