Skip to content

[EventDispatcher] Add events attribute of the kernel.event_listener tag #61222

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

Conversation

santysisi
Copy link
Contributor

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? yes
Issues Fix #61218
License MIT

Added

  • Support for the new events attribute in the kernel.event_listener tag, enabling registration of a listener for multiple events at once.

Deprecated

  • The event attribute in kernel.event_listener is now deprecated and will be removed in Symfony 8.0.
    • Using the event attribute will trigger a deprecation warning.
    • Defining both event and events will throw an InvalidArgumentException to avoid configuration conflicts.

@santysisi santysisi requested review from lyrixx and chalasr as code owners July 24, 2025 04:24
@carsonbot carsonbot added this to the 7.4 milestone Jul 24, 2025
@santysisi santysisi force-pushed the feature/kernel-event_listener-events-attribute branch 2 times, most recently from 6513db5 to f801995 Compare July 24, 2025 04:40
@santysisi santysisi force-pushed the feature/kernel-event_listener-events-attribute branch from f801995 to 61e8043 Compare July 24, 2025 04:54
@@ -17,7 +17,8 @@
],
"require": {
"php": ">=8.2",
"symfony/event-dispatcher-contracts": "^2.5|^3"
"symfony/event-dispatcher-contracts": "^2.5|^3",
"symfony/deprecation-contracts": "^2.5|^3"
Copy link
Contributor Author

@santysisi santysisi Jul 24, 2025

Choose a reason for hiding this comment

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

I added this dependency to the component because I'm using the trigger_deprecation() function.

@@ -24,7 +24,7 @@
"symfony/dependency-injection": "^7.2|^8.0",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/error-handler": "^7.3|^8.0",
"symfony/event-dispatcher": "^6.4|^7.0|^8.0",
"symfony/event-dispatcher": "^7.4|^8.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm bumping the version to 7.4 in order to use the new events attribute instead of event.
Please let me know if you'd prefer a different strategy or approach. I'm happy to adjust and avoid the version bump if needed 😄

@@ -23,7 +23,7 @@
"symfony/config": "^7.3|^8.0",
"symfony/dependency-injection": "^6.4.11|^7.1.4|^8.0",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/event-dispatcher": "^6.4|^7.0|^8.0",
"symfony/event-dispatcher": "^7.4|^8.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here

@GromNaN
Copy link
Member

GromNaN commented Jul 24, 2025

Deprecating and renaming the "event" parameter of the tag has too much impact (as shown by the diff in tests). That will cause a lot of maintenance burden for projects that define event listeners in configuration directly.

Instead, I think the event listener tag can be repeated for each listened event.

@nicolas-grekas
Copy link
Member

I'm not sure that's the right approach. Can't we add multiple kernel.event_listener tags instead? That should be already supported.

@@ -28,6 +28,10 @@ DoctrineBridge

* Deprecate `UniqueEntity::getRequiredOptions()` and `UniqueEntity::getDefaultOption()`

EventDispatcher
---------------
* Deprecate attribute `event` of the `kernel.event_listener` tag in favor of `events` attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Deprecate attribute `event` of the `kernel.event_listener` tag in favor of `events` attribute
* Deprecate attribute `event` of the `kernel.event_listener` tag in favor of `events` attribute

Copy link
Contributor

Choose a reason for hiding this comment

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

There are also two spaces between "tag" and "in".

Copy link
Member

Choose a reason for hiding this comment

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

This deprecation must be reverted.

@@ -1,6 +1,11 @@
CHANGELOG
=========

7.4
---
* Add `events` attribute of the `kernel.event_listener` tag
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Add `events` attribute of the `kernel.event_listener` tag
* Add `events` attribute of the `kernel.event_listener` tag

@OskarStark
Copy link
Contributor

We should keep tests using also the old event and mark it with @group legacy to ensure, this is still working

Copy link
Contributor

@alex-dev alex-dev left a comment

Choose a reason for hiding this comment

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

Looking at how much changes this implementation for a minor QoL improvement bring, it is clear we should consider a less invasive approach.

I see no reason to go with supporting multiple events in the same tag. Considering a service can already have multiple kernel.event_listener targetting the same method, keeping the nesting flat and having a single event per tag ensure compatibility with everything without any breaking change.
It even matches better with the final runtime implementation: the listener method is registered multiple time in the dispatcher.

@santysisi
Copy link
Contributor Author

Hi everyone 👋,

Thank you all for taking the time to review this PR and explain why this approach might not be ideal. I understand and agree with your points, so I’ll go ahead and close this PR.

Once again, I really appreciate you all for sharing your perspectives ❤️

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.

#[AsEventListener] does not handle union types
7 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy