-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[EventDispatcher] Throw exception when listener method cannot be resolved #50775
[EventDispatcher] Throw exception when listener method cannot be resolved #50775
Conversation
0319d14
to
0434c2e
Compare
e3797d3
to
838a2fc
Compare
This should target 5.4 to me since it's a bugfix. |
838a2fc
to
1339e8d
Compare
1339e8d
to
20ae84e
Compare
@nicolas-grekas I've rebased the PR |
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. |
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 deprecate documented way of using this attribute. |
Totally. I missed this was a new feature.
I would advise against this. It'd be needlessly rigid. |
20ae84e
to
36ef0b1
Compare
There 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
Outdated
Show resolved
Hide resolved
src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php
Outdated
Show resolved
Hide resolved
36ef0b1
to
ccbe179
Compare
CI failures seems unrelated |
src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php
Outdated
Show resolved
Hide resolved
ccbe179
to
eff4526
Compare
There 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
Outdated
Show resolved
Hide resolved
…hod cannot be resolved
eff4526
to
2b3497f
Compare
@nicolas-grekas done! |
Thank you @nikophil. |
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 from this 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