Skip to content

Commit

Permalink
Merge branch 'fix_has_listeners_issue' of https://github.com/imanghaf…
Browse files Browse the repository at this point in the history
…oori1/laravel_framework into imanghafoori1-fix_has_listeners_issue
  • Loading branch information
taylorotwell committed Feb 10, 2020
2 parents 18791d9 + 28df132 commit 4786be9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 4786be9

Please sign in to comment.