Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
dersonsena committed May 28, 2021
1 parent 73d311c commit b483c3b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Yii2TacticianCommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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();
Expand All @@ -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]);
}
}

0 comments on commit b483c3b

Please sign in to comment.