Skip to content

Commit fce40d3

Browse files
committed
feat: add support for controller middleware
1 parent 5d2f40b commit fce40d3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Router.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,11 +933,17 @@ private static function invoke($handler, $params = [])
933933

934934
// First check if is a static method, directly trying to invoke it.
935935
// If isn't a valid static method, we will try as a normal method invocation.
936-
if (call_user_func_array([new $controller(), $method], $params) === false) {
937-
// Try to call the method as a non-static method. (the if does nothing, only avoids the notice)
938-
if (forward_static_call_array([$controller, $method], $params) === false)
939-
;
936+
$instance = new $controller();
937+
938+
if (method_exists($instance, '__middleware')) {
939+
$middlewareResponse = $instance->__middleware($method, $params);
940+
941+
if ($middlewareResponse === false) {
942+
return;
943+
}
940944
}
945+
946+
call_user_func_array([$instance, $method], $params);
941947
} elseif (strpos($handler, ':') !== false) {
942948
$middlewareParams = [];
943949

0 commit comments

Comments
 (0)