-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[EventDispatcher] check for method to exist #18388
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
Actually, this could be seen as breaking the contract given by the parent class which strictly seen doesn't allow to throw an exception here. An alternative fix would be to keep records about the listener priorities in the |
@@ -104,6 +104,10 @@ public function getListeners($eventName = null) | |||
*/ | |||
public function getListenerPriority($eventName, $listener) | |||
{ | |||
if (!method_exists($this->dispatcher, 'getListenerPriority')) { | |||
throw new \LogicException(sprintf('The wrapped event dispatcher\'s class ("%s") does not implement the getListenerPriority() method.', get_class($this->dispatcher))); |
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.
another solution would be to fallback to the behavior used by the traceable dispatcher in 2.7 and older: register the listener at priority 0. It is better than breaking the dispatching entirely IMO (especially given that all core implementations have this method implemented so most people will have the right priority anyway)
Updated here to treat 0 as the default listener priority. |
Thank you @xabbuh. |
This PR was merged into the 2.8 branch. Discussion ---------- [EventDispatcher] check for method to exist | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16301 (comment) | License | MIT | Doc PR | This change must be reverted after being merged into the `3.0` branch (the `getListenerPriority()` method was added to the interface in Symfony 3.0). Commits ------- 78ae2ad [EventDispatcher] check for method to exist
This change must be reverted after being merged into the
3.0
branch (thegetListenerPriority()
method was added to the interface in Symfony 3.0).