Skip to content

Event listener from attribute should not have a default priority #43757

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 1 commit into from

Conversation

aschempp
Copy link
Contributor

Q A
Branch? 5.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets ~
License MIT
Doc PR ~

There is a difference between a service not having a priority and a priority of being 0. If there is no priority (or it is null), the event listener/service can provide a method to return the priority. This would be disabled by a default value of 0.

see https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php#L68-L72

@nicolas-grekas
Copy link
Member

Nice catch. Can you please add a test case so that we're reminded about that behavior?

@aschempp
Copy link
Contributor Author

Reviewing this feature, I realized that the RegisterListenersPass which registers event listener does not actually implement PriorityTaggedServiceTrait! https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php#L94

Now this

  1. obviously makes my PR obsolete
  2. begs the question whether the listener should be changed to use the trait? 😅

@derrabus
Copy link
Member

I don't quite get why I would configure an event listener by attribute but set the priority via method call. If I use the attribute, why don't I use the attribute for everything?

@nicolas-grekas
Copy link
Member

I realized that the RegisterListenersPass which registers event listener does not actually implement PriorityTaggedServiceTrait!

Oh indeed, priority is managed by the EventDispatcher at runtime.

@aschempp
Copy link
Contributor Author

I don't quite get why I would configure an event listener by attribute but set the priority via method call. If I use the attribute, why don't I use the attribute for everything?

Yeah thats a good question, and maybe why this has never been added to event listeners. As far as I understand, this was added in #33628 to support priority for services that were tagged through (interface) autoconfiguration. I guess this has never become relevant for event listeners because one could use the EventSubscriber pattern in that case (which is not available for e.g. security voters).

@aschempp aschempp deleted the bugfix/attribute-priority branch October 28, 2021 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants