From 830a643a56d7580698ec3236364c29863faeb6cb Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Thu, 21 Nov 2024 19:15:04 -0500 Subject: [PATCH] - Fixed route generating (removed methods) --- src/Extension/UrlExtension.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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'])); } }