|
|
|
|
@ -152,7 +152,7 @@ class Router
|
|
|
|
|
if (!isset($this->routesByMethod[$method])) {
|
|
|
|
|
$this->routesByMethod[$method] = [];
|
|
|
|
|
}
|
|
|
|
|
$this->routesByMethod[$method][] = $route;
|
|
|
|
|
$this->routesByMethod[$method][count($this->routes) - 1] = $route;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $route;
|
|
|
|
|
@ -270,19 +270,15 @@ class Router
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fast path: check method-specific routes first, then wildcard routes (only on first routing attempt)
|
|
|
|
|
$methodsToCheck = [$requestMethod, '*'];
|
|
|
|
|
foreach ($methodsToCheck as $method) {
|
|
|
|
|
if (isset($this->routesByMethod[$method])) {
|
|
|
|
|
foreach ($this->routesByMethod[$method] as $route) {
|
|
|
|
|
$candidates = ($this->routesByMethod[$requestMethod] ?? []) + ($this->routesByMethod['*'] ?? []);
|
|
|
|
|
ksort($candidates);
|
|
|
|
|
foreach ($candidates as $routeIndex => $route) {
|
|
|
|
|
if ($route->matchUrl($requestUrl, $this->caseSensitive)) {
|
|
|
|
|
$this->executedRoute = $route;
|
|
|
|
|
// Set iterator position to this route for potential next() calls
|
|
|
|
|
$this->index = array_search($route, $this->routes, true);
|
|
|
|
|
$this->index = $routeIndex;
|
|
|
|
|
return $route;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If no exact match found, check all routes for 405 (method not allowed) cases
|
|
|
|
|
// This maintains the original behavior where we capture routes that match URL but not method
|
|
|
|
|
|