Skip to content

Commit

Permalink
feat: allow middleware with params
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Dec 15, 2024
1 parent 79dc792 commit 3d7ec1e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ private static function invoke($handler, $params = [])
$handler,
$params
);
} elseif (stripos($handler, '@') !== false) {
} else if (stripos($handler, '@') !== false) {
list($controller, $method) = explode('@', $handler);

if (!class_exists($controller)) {
Expand All @@ -881,8 +881,15 @@ private static function invoke($handler, $params = [])
if (call_user_func_array([new $controller(), $method], $params) === false) {
// Try to call the method as a non-static method. (the if does nothing, only avoids the notice)
if (forward_static_call_array([$controller, $method], $params) === false)
;
;
}
} else if (strpos($handler, ':') !== false) {
$middlewareParams = [];

$middlewareParams = explode(':', $handler);
$middleware = array_shift($middlewareParams);

static::$namedMiddleware[$middleware](explode('|', $middlewareParams[0] ?? ''));
}
}
}

0 comments on commit 3d7ec1e

Please sign in to comment.