Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

hranicka
Copy link
Contributor

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"?

@@ -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.
Copy link
Contributor Author

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?

Copy link
Member

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

@fprochazka
Copy link
Member

Wow, great job! I'm gonna try real hard to look into this soon.

@Tharos
Copy link

Tharos commented Nov 25, 2015

👍 For this, I'd love to use Closure for callbacks.

foreach ($this->listeners as $event => $prioritized) {
foreach ($prioritized as $listeners) {
foreach ($listeners as $listener) {
if ($listener == $subscriber) {
Copy link
Member

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

@fprochazka
Copy link
Member

fprochazka commented May 1, 2016

This seems good enough for me: 69806d1...b6fc86b

@fprochazka
Copy link
Member

Thank you! And sorry for not getting to it sooner.

@fprochazka fprochazka closed this May 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants