From 5c81da7b77a1b061ef3c45c18f61d28539ed4c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Sun, 11 Oct 2015 11:35:56 +0200 Subject: [PATCH] [BUGFIX] Bugfixes - Made sure that urls are always presented in the correct order - Ignored RouterGroup in controllerUrlMap --- src/Pecee/SimpleRouter/RouterBase.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index 1a85a2d..bbe1ba0 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -61,11 +61,13 @@ class RouterBase { } $route->addSettings($mergedSettings); - if(!($route instanceof RouterGroup) && is_array($newPrefixes) && count($newPrefixes) && $backstack) { - $route->setUrl( join('/', $newPrefixes) . $route->getUrl() ); - } + if(!($route instanceof RouterGroup)) { + if(is_array($newPrefixes) && count($newPrefixes) && $backstack) { + $route->setUrl( join('/', $newPrefixes) . $route->getUrl() ); + } - $this->controllerUrlMap[] = $route; + $this->controllerUrlMap[] = $route; + } $this->currentRoute = $route; if($route instanceof RouterGroup && is_callable($route->getCallback())) { @@ -88,6 +90,11 @@ class RouterBase { $this->processRoutes($this->routes); + // Make sure the urls is in the right order when comparing + usort($this->controllerUrlMap, function($a, $b) { + return strcmp($b->getUrl(), $a->getUrl()); + }); + foreach($this->controllerUrlMap as $route) { $routeMatch = $route->matchRoute($this->requestMethod, rtrim($this->requestUri, '/') . '/');