diff --git a/src/ActionServiceProvider.php b/src/ActionServiceProvider.php index a1bbf0f..57c5325 100644 --- a/src/ActionServiceProvider.php +++ b/src/ActionServiceProvider.php @@ -13,9 +13,7 @@ class ActionServiceProvider extends ServiceProvider public function boot() { $this->app->extend('events', function ($dispatcher, $app) { - return (new EventDispatcher($app))->setQueueResolver(function () use ($app) { - return $app->make(QueueFactoryContract::class); - }); + return new EventDispatcherDecorator($dispatcher, $app); }); $this->app->extend(IlluminateBusDispatcher::class, function ($dispatcher, $app) { diff --git a/src/EventDispatcher.php b/src/EventDispatcher.php deleted file mode 100644 index 6c16860..0000000 --- a/src/EventDispatcher.php +++ /dev/null @@ -1,20 +0,0 @@ -container->make($class) instanceof Action) { - return Str::parseCallback($listener, 'runAsListener'); - } - - return [$class, $method]; - } -} \ No newline at end of file diff --git a/src/EventDispatcherDecorator.php b/src/EventDispatcherDecorator.php new file mode 100644 index 0000000..d0d15df --- /dev/null +++ b/src/EventDispatcherDecorator.php @@ -0,0 +1,88 @@ +dispatcher = $dispatcher; + $this->container = $container; + } + + public function listen($events, $listener) + { + if ($this->isActionFullyQualifiedName($listener)) { + $listener = $listener . '@runAsListener'; + } + + return $this->dispatcher->listen($events, $listener); + } + + public function isActionFullyQualifiedName($listener) + { + if (! is_string($listener)) { + return false; + } + + [$class, $method] = Str::parseCallback($listener); + + if (! is_null($method)) { + return false; + } + + return $this->container->make($class) instanceof Action; + } + + public function hasListeners($eventName) + { + return $this->dispatcher->hasListeners($eventName); + } + + public function subscribe($subscriber) + { + return $this->dispatcher->subscribe($subscriber); + } + + public function until($event, $payload = []) + { + return $this->dispatcher->until($event, $payload); + } + + public function dispatch($event, $payload = [], $halt = false) + { + return $this->dispatcher->dispatch($event, $payload, $halt); + } + + public function push($event, $payload = []) + { + return $this->dispatcher->push($event, $payload); + } + + public function flush($event) + { + return $this->dispatcher->flush($event); + } + + public function forget($event) + { + return $this->dispatcher->forget($event); + } + + public function forgetPushed() + { + return $this->dispatcher->forgetPushed(); + } + + public function __call($method, $parameters) + { + return $this->dispatcher->{$method}(...$parameters); + } +} \ No newline at end of file