-
Notifications
You must be signed in to change notification settings - Fork 64
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
EventManager: Alow callable as listeners [Closes #57] #82
Conversation
@@ -171,7 +171,7 @@ public function hasListeners($eventName) | |||
* Adds an event listener that listens on the specified events. | |||
* | |||
* @param string|array $events The event(s) to listen on. | |||
* @param Doctrine\Common\EventSubscriber|array $subscriber The listener object. | |||
* @param Doctrine\Common\EventSubscriber|array|callable $subscriber The listener object. |
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.
As @vojtech-dobes said somewhere, Doctrine\Common\EventSubscriber does not exist.
The dependency is missing?
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.
It exists, just not in this repo :)
Wow, great job! I'm gonna try real hard to look into this soon. |
👍 For this, I'd love to use |
foreach ($this->listeners as $event => $prioritized) { | ||
foreach ($prioritized as $listeners) { | ||
foreach ($listeners as $listener) { | ||
if ($listener == $subscriber) { |
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.
this looks like a bug to me
This seems good enough for me: 69806d1...b6fc86b |
Thank you! And sorry for not getting to it sooner. |
Closes #57
In some cases I would like use dynamic listeners or use callbacks as listeners.
It was not possible before and this PR adds the functionality requested in #57.
In cases when I would like use callbacks almost everytime is it possible to create Subscriber which supplies the functionality. So I'm not 100% sure that the feature is really needed.
Does anybody has a specific use case when callback or __call methods are better than "real classes with real methods"?