Skip to content

Commit

Permalink
The same middleware prevented it from working twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
izniburak committed Nov 24, 2020
1 parent 9adeaf3 commit 895c97e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/RouterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class RouterCommand
*/
protected $middlewares = [];

/**
* @var array
*/
protected $markedMiddlewares = [];

/**
* RouterCommand constructor.
*
Expand Down Expand Up @@ -302,8 +307,14 @@ protected function runMiddleware(string $command, string $middleware, array $par
{
$middlewareMethod = 'handle'; // For now, it's constant.
$controller = $this->resolveClass($middleware, $info['path'], $info['namespace']);

if (in_array($className = get_class($controller), $this->markedMiddlewares)) {
return true;
}
array_push($this->markedMiddlewares, $className);

if (!method_exists($controller, $middlewareMethod)) {
return $this->exception("{$middlewareMethod}() method is not found in {$command} class.");
return $this->exception("{$middlewareMethod}() method is not found in {$middleware} class.");
}

$parameters = $this->resolveCallbackParameters(new ReflectionMethod($controller, $middlewareMethod), $params);
Expand Down

0 comments on commit 895c97e

Please sign in to comment.