Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
May 3, 2016
Merged

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Mar 31, 2016

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).

@xabbuh
Copy link
Member Author

xabbuh commented Mar 31, 2016

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 TraceableEventDispatcher (which on the other hand would not work when the listener was registered on the wrapped dispatcher directly, thus bypassing the outer dispatcher).

@@ -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)));
Copy link
Member

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)

@fabpot
Copy link
Member

fabpot commented Apr 28, 2016

@xabbuh Any feedback regarding @stof comment?

@xabbuh
Copy link
Member Author

xabbuh commented May 3, 2016

Updated here to treat 0 as the default listener priority.

@fabpot
Copy link
Member

fabpot commented May 3, 2016

Thank you @xabbuh.

@fabpot fabpot merged commit 78ae2ad into symfony:2.8 May 3, 2016
fabpot added a commit that referenced this pull request May 3, 2016
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
@xabbuh xabbuh deleted the pr-16198 branch May 3, 2016 19:03
This was referenced May 9, 2016
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.

5 participants