From 3d7ec1e42cd5d5c7bddf13a64faa7ede77a9013a Mon Sep 17 00:00:00 2001 From: mychidarko Date: Sun, 15 Dec 2024 07:59:26 +0000 Subject: [PATCH] feat: allow middleware with params --- src/Router.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Router.php b/src/Router.php index 74fb638..6c0f24c 100644 --- a/src/Router.php +++ b/src/Router.php @@ -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)) { @@ -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] ?? '')); } } }