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

[6.x] Fixes issue for has_listeners method on dispatcher #31403

Merged
merged 1 commit into from Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Illuminate/Events/Dispatcher.php
Expand Up @@ -104,7 +104,17 @@ protected function setupWildcardListen($event, $listener)
*/
public function hasListeners($eventName)
{
return isset($this->listeners[$eventName]) || isset($this->wildcards[$eventName]);
$hasWildcard = function ($eventName) {
foreach ($this->wildcards as $key => $listeners) {
if (Str::is($key, $eventName)) {
return true;
}
}

return false;
};

return isset($this->listeners[$eventName]) || isset($this->wildcards[$eventName]) || $hasWildcard($eventName);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Events/EventsDispatcherTest.php
Expand Up @@ -192,6 +192,7 @@ public function testWildcardListenersCanBeFound()
//
});
$this->assertTrue($d->hasListeners('foo.*'));
$this->assertTrue($d->hasListeners('foo.bar'));
}

public function testEventPassedFirstToWildcards()
Expand Down