diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index a96b761..b4cc843 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -160,11 +160,13 @@ PATTERN; $this->eventExecute(UrlRegisterRouteEvent::class, $name, $array); } - protected function findRoute(string $name, string $method = "GET") : false|array + protected function findRoute(string $name, string $method = "*") : false|array { foreach($this->routes as $route) { - if ( ($route['name'] === $name) && in_array(strtoupper($method), $route['routeMethods']) ) { - return $route; + if ( $route['name'] === $name ) { + if ($method === '*' || in_array(strtoupper($method), $route['routeMethods']) ) { + return $route; + } } } @@ -287,7 +289,7 @@ PATTERN; if ($default ?? false) { $value = $default; } - elseif ( ! str_contains($route, "[{$matches[0][0]}]") && ! str_contains($route, "[/{$matches[0][0]}]") && $this->enforceExistingArguments) { + elseif ( $this->enforceExistingArguments && ! preg_match(sprintf("/\[\/?%s]/i", $item[0]), $route) ) { throw new \RuntimeException(sprintf("Error while preparing route %s : could not match variable '%s' into given arguments ( %s ) from %s::%s", $route, $variable, json_encode($arguments), $routeParam['class'], $routeParam['classMethod'])); } }