Skip to content

Commit 895c97e

Browse files
committed
The same middleware prevented it from working twice.
1 parent 9adeaf3 commit 895c97e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/RouterCommand.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class RouterCommand
4848
*/
4949
protected $middlewares = [];
5050

51+
/**
52+
* @var array
53+
*/
54+
protected $markedMiddlewares = [];
55+
5156
/**
5257
* RouterCommand constructor.
5358
*
@@ -302,8 +307,14 @@ protected function runMiddleware(string $command, string $middleware, array $par
302307
{
303308
$middlewareMethod = 'handle'; // For now, it's constant.
304309
$controller = $this->resolveClass($middleware, $info['path'], $info['namespace']);
310+
311+
if (in_array($className = get_class($controller), $this->markedMiddlewares)) {
312+
return true;
313+
}
314+
array_push($this->markedMiddlewares, $className);
315+
305316
if (!method_exists($controller, $middlewareMethod)) {
306-
return $this->exception("{$middlewareMethod}() method is not found in {$command} class.");
317+
return $this->exception("{$middlewareMethod}() method is not found in {$middleware} class.");
307318
}
308319

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

0 commit comments

Comments
 (0)