Skip to content

Commit 45833b9

Browse files
2.1.3
- hotfix миддлваров
1 parent 74de2b9 commit 45833b9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/AppRouter.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,13 @@ public static function dispatch()
626626
// Fetch method and URI from somewhere
627627
self::$routeInfo = $routeInfo = (self::$dispatcher->dispatcher())->dispatch(self::$httpMethod, self::$uri);
628628

629+
// несмотря на то, что $routeInfo - Arris\AppRouter\FastRoute\Dispatcher\Result\Matched - доступ по [N] возможен, поскольку
630+
// класс реализует метод ArrayAccess
631+
//
629632
$state = $routeInfo[0]; // тут ВСЕГДА что-то есть
630633
$handler = $routeInfo[1] ?? [];
631634
$method_parameters = $routeInfo[2] ?? [];
632635

633-
// Так нельзя:
634-
// [$state, $handler, $method_parameters] = $routeInfo + [null, null, []];
635-
// Fatal error: Uncaught TypeError: Unsupported operand types: Arris\AppRouter\FastRoute\Dispatcher\Result\Matched + array
636-
637636
// dispatch errors
638637
if ($state === Dispatcher::NOT_FOUND) {
639638
throw new AppRouterNotFoundException("URL not found", 404, [
@@ -655,8 +654,8 @@ public static function dispatch()
655654
]);
656655
}
657656

658-
// Route Rule доступен только для Matched-роутов.
659-
self::$routeRule = $rule = $routeInfo[3] ?? [];
657+
// Route Rule доступен только для Matched-роутов - 3=extra parameters - он всегда есть и не пустой
658+
self::$routeRule = $rule = $routeInfo[3];
660659

661660
$actor = self::compileHandler($handler, false, 'default');
662661

@@ -899,7 +898,14 @@ private static function compileHandler($handler, bool $is_middleware = false): a
899898

900899
// [ \Path\To\Class:class, "method" ]
901900
if (is_array($handler)) {
902-
[$class, $method] = $handler + [null, '__invoke'];
901+
// [$class, $method] = $handler + [null, '__invoke']; // Recommended by DeepSeek
902+
903+
if (count($handler) == 2) {
904+
list($class, $method) = $handler;
905+
} else {
906+
$class = $handler[0];
907+
$method = '__invoke';
908+
}
903909

904910
self::checkClassExists($class);
905911
self::checkMethodExists($class, $method);

0 commit comments

Comments
 (0)