33namespace League\Tactician;
44
55use Closure;
6+ use League\Tactician\Exception\InvalidCommandException;
67
78/**
89 * Receives a command and sends it through a chain of middleware for processing.
@@ -25,11 +26,15 @@ public function __construct(array $middleware)
2526 /**
2627 * Executes the given command and optionally returns a value
2728 *
28- * @param Command $command
29+ * @param object $command
2930 * @return mixed
3031 */
31- public function handle(Command $command)
32+ public function handle($command)
3233 {
34+ if (!is_object($command)) {
35+ throw InvalidCommandException::forUnknownValue($command);
36+ }
37+
3338 $middlewareChain = $this->middlewareChain;
3439 return $middlewareChain($command);
3540 }
@@ -40,12 +45,12 @@ public function handle(Command $command)
4045 */
4146 private function createExecutionChain($middlewareList)
4247 {
43- $lastCallable = function (Command $command) {
48+ $lastCallable = function ($command) {
4449 // the final callable is a no-op
4550 };
4651
4752 while ($middleware = array_pop($middlewareList)) {
48- $lastCallable = function (Command $command) use ($middleware, $lastCallable) {
53+ $lastCallable = function ($command) use ($middleware, $lastCallable) {
4954 return $middleware->execute($command, $lastCallable);
5055 };
5156 }
0 commit comments