From b483c3b380e687bad7d7eb663fafc00031e247b3 Mon Sep 17 00:00:00 2001 From: Kilderson Sena Date: Fri, 28 May 2021 11:04:41 -0300 Subject: [PATCH] mend --- src/Yii2TacticianCommandBus.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Yii2TacticianCommandBus.php b/src/Yii2TacticianCommandBus.php index 72429bb..5b21d5a 100644 --- a/src/Yii2TacticianCommandBus.php +++ b/src/Yii2TacticianCommandBus.php @@ -40,8 +40,6 @@ public function init() */ public function handle($command, array $parameters = []) { - $callable = [$this->commandBus, 'handle']; - if (is_string($command)) { if (empty($parameters)) { throw new InvalidArgumentException("You must provide parameters when command is a string path."); @@ -50,12 +48,12 @@ public function handle($command, array $parameters = []) /** @var \DersonSena\Yii2Tactician\Handler $handleObject */ $handleObject = Yii::$container->get($command); - if (!($handleObject instanceof Handle)) { - throw new RuntimeException("Handle class must implements '" . Handle::class . "' interface."); + if (!($handleObject instanceof Handler)) { + throw new RuntimeException("Handler class '" . get_class($handleObject) . "' must implements '" . Handler::class . "' interface."); } if (!method_exists($handleObject, 'handle')) { - throw new RuntimeException("Handle class '{$handleObject::class}' must be a handle() method."); + throw new RuntimeException("Handler class '" . get_class($handleObject) . "' must be a handle method."); } $commandClass = $handleObject->commandClassName(); @@ -71,9 +69,9 @@ public function handle($command, array $parameters = []) throw new RuntimeException("Command class must implements '" . Command::class . "' interface."); } - return $handleObject->handle($command); + return call_user_func_array([$handleObject, 'handle'], [$command]); } - return call_user_func_array($callable, [$command]); + return call_user_func_array([$this->commandBus, 'handle'], [$command]); } }