Skip to content

Commit 3d7ec1e

Browse files
committed
feat: allow middleware with params
1 parent 79dc792 commit 3d7ec1e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Router.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ private static function invoke($handler, $params = [])
865865
$handler,
866866
$params
867867
);
868-
} elseif (stripos($handler, '@') !== false) {
868+
} else if (stripos($handler, '@') !== false) {
869869
list($controller, $method) = explode('@', $handler);
870870

871871
if (!class_exists($controller)) {
@@ -881,8 +881,15 @@ private static function invoke($handler, $params = [])
881881
if (call_user_func_array([new $controller(), $method], $params) === false) {
882882
// Try to call the method as a non-static method. (the if does nothing, only avoids the notice)
883883
if (forward_static_call_array([$controller, $method], $params) === false)
884-
;
884+
;
885885
}
886+
} else if (strpos($handler, ':') !== false) {
887+
$middlewareParams = [];
888+
889+
$middlewareParams = explode(':', $handler);
890+
$middleware = array_shift($middlewareParams);
891+
892+
static::$namedMiddleware[$middleware](explode('|', $middlewareParams[0] ?? ''));
886893
}
887894
}
888895
}

0 commit comments

Comments
 (0)