Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[EventDispatcher] Throw exception when listener method cannot be resolved#50775
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
0319d14
to0434c2e
Comparee3797d3
to838a2fc
CompareThis should target 5.4 to me since it's a bugfix. |
838a2fc
to1339e8d
Compare1339e8d
to20ae84e
Compare@nicolas-grekas I've rebased the PR |
GromNaN commentedJun 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thank you for your findings on this bug.
This looks like a new feature. Even if there is currently a runtime exception for this situation, I don't think we should support it as a bugfix. I see situations where the "only public method" will fail and the developers will have to rework their configuration while it would be working previously:
For brevity, developers should set the |
ok let's do this: I'll split the PR and in the bugfix I'll only throw an exception if the resolved method does not exist
indeed, there will be a failure in these cases, but for both cases, we don't have any way to resolve the method name, then their listener declaration becomes invalid. And since the error will occur in compile time, I think this is acceptable |
👍🏻 Sounds like a plan. |
nikophil commentedJun 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This is just an idea, but since listeners are callables and not actual services, maybe in 7.0 we should allow |
I wouldn't bother developers with such a restriction. We're not going to deprecatedocumented way of using this attribute. |
nicolas-grekas commentedJun 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Totally. I missed this was a new feature.
I would advise against this. It'd be needlessly rigid. |
20ae84e
to36ef0b1
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM, after few changes.
src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
36ef0b1
toccbe179
CompareCI failures seems unrelated |
src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ccbe179
toeff4526
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
One minor thing. Can you please also update the commit+PR messages to make them tell what this does?
src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
…hod cannot be resolved
eff4526
to2b3497f
Compare@nicolas-grekas done! |
Thank you@nikophil. |
Uh oh!
There was an error while loading.Please reload this page.
while working on#50687 I've discovered bugs on how the method for listener is resolved:
Given this code:
A listener on
MyListenerNotInvokable::onKernelRequest()
is registered, and then an error is dispatched at runtime when the event is dispatched:Error: Call to undefined method App\EventListener\MyListenerNotInvokable::onKernelRequest()
The problem comes fromthis code: since the
method
is omitted in tag definition, we "camelize" the event's name. We then try to fallback on__invoke
but because it does not exist, the wrong method name is kept.this PR fixes this behavior by throwing an exception at compile time if neither the camlized method exist, not the
__invoke
method.ping@GromNaN