8000 [Doctrine Bridge] document priority for doctrine.event_listener tag by dmaicher · Pull Request #9944 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Doctrine Bridge] document priority for doctrine.event_listener tag #9944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
54 changes: 54 additions & 0 deletions doctrine/event_listeners_subscribers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,57 @@ 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


8000 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please keep the naming convention here? e.g, using app.listener.high_priority? I would also remove My prefix on class names, I don't think we use such names elsewhere in the docs.

Copy link
Contributor Author
@dmaicher dmaicher Jun 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually followed the naming convention (for the service id) of the other examples in this file 😉

If you want I can rename all of them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, as this targets 2.8 why not, but then this would better be done in another PR. Let's wait for other maintainers opinion before making this change. Thanks!

class: AppBundle\EventListener\MyHighPriorityListener
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the scope of this PR but I don't think we should use the same namespace for kernel listener and doctrine listener (like form listeners should remain in App\Form\Listener).

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

<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">

<services>
<service id="my.listener.with_high_priority" class="AppBundle\EventListener\MyHighPriorityListener">
<tag name="doctrine.event_listener" event="postPersist" priority="10" />
</service>
<service id="my.listener.with_low_priority" class="AppBundle\EventListener\MyLowPriorityListener">
<tag name="doctrine.event_listener" event="postPersist" priority="1" />
</service>
</services>
</container>

.. 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))
;
0