From 707557226a27a71499123600d50f99eb29872beb Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Fri, 15 Nov 2019 12:54:47 +0000 Subject: [PATCH] Use action object as job handler See #28 --- src/BusDispatcher.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/BusDispatcher.php b/src/BusDispatcher.php index 1f88446..33cc9e9 100644 --- a/src/BusDispatcher.php +++ b/src/BusDispatcher.php @@ -6,17 +6,16 @@ class BusDispatcher extends IlluminateDispatcher { - public function getCommandHandler($command) + public function dispatchNow($command, $handler = null) { - if ($command instanceof Action) { - return new class() { - public function handle($action) - { - return $action->runAsJob(); - } - }; + if (! $command instanceof Action) { + return parent::dispatchNow($command, $handler); } - return parent::getCommandHandler($command); + $callback = function ($command) { + return $this->container->call([$command, 'runAsJob']); + }; + + return $this->pipeline->send($command)->through($this->pipes)->then($callback); } }