From 28df132fe0018edb66d0d0102ff13d445184c234 Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Sat, 8 Feb 2020 18:07:41 +0330 Subject: [PATCH] Fixes issue for has_listeners method on dispatcher --- src/Illuminate/Events/Dispatcher.php | 12 +++++++++++- tests/Events/EventsDispatcherTest.php | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index 1e193cc889cd..0b35a320c12c 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -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); } /** diff --git a/tests/Events/EventsDispatcherTest.php b/tests/Events/EventsDispatcherTest.php index 55b55428732a..548f0f9f55a3 100755 --- a/tests/Events/EventsDispatcherTest.php +++ b/tests/Events/EventsDispatcherTest.php @@ -192,6 +192,7 @@ public function testWildcardListenersCanBeFound() // }); $this->assertTrue($d->hasListeners('foo.*')); + $this->assertTrue($d->hasListeners('foo.bar')); } public function testEventPassedFirstToWildcards()