From 73d311cb3b0f8cf021ce811279d0bb4e6a9b52aa Mon Sep 17 00:00:00 2001 From: Kilderson Sena Date: Fri, 28 May 2021 10:40:11 -0300 Subject: [PATCH] fixing handle method return --- src/Yii2TacticianCommandBus.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Yii2TacticianCommandBus.php b/src/Yii2TacticianCommandBus.php index ac25535..72429bb 100644 --- a/src/Yii2TacticianCommandBus.php +++ b/src/Yii2TacticianCommandBus.php @@ -49,6 +49,15 @@ 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 (!method_exists($handleObject, 'handle')) { + throw new RuntimeException("Handle class '{$handleObject::class}' must be a handle() method."); + } + $commandClass = $handleObject->commandClassName(); if (!class_exists($commandClass)) { @@ -62,7 +71,7 @@ public function handle($command, array $parameters = []) throw new RuntimeException("Command class must implements '" . Command::class . "' interface."); } - return call_user_func_array($callable, [$command]); + return $handleObject->handle($command); } return call_user_func_array($callable, [$command]);