From c2cf2334e7b7676623c8abdcb4600c41bed2cb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Tue, 27 Oct 2015 14:01:19 +0100 Subject: [PATCH] [OPTIMISATION] Optimised router handling - router will now use the order provided when loading routes. --- src/Pecee/SimpleRouter/RouterBase.php | 8 -------- src/Pecee/SimpleRouter/RouterRoute.php | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index a86c9f2..d282a17 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -100,14 +100,6 @@ class RouterBase { // Loop through each route-request $this->processRoutes($this->routes); - // Make sure the urls is in the right order when comparing - usort($this->controllerUrlMap, function($a, $b) { - if(stripos($b->getUrl(), '{') !== false) { - return $a->getUrl(); - } - return strcmp($b->getUrl(), $a->getUrl()); - }); - $routeNotAllowed = false; /* @var $route RouterEntry */ diff --git a/src/Pecee/SimpleRouter/RouterRoute.php b/src/Pecee/SimpleRouter/RouterRoute.php index 97dd519..cf1a7e9 100644 --- a/src/Pecee/SimpleRouter/RouterRoute.php +++ b/src/Pecee/SimpleRouter/RouterRoute.php @@ -49,7 +49,7 @@ class RouterRoute extends RouterEntry { // Check if url parameter count matches if(stripos($url, $routeMatch) === 0) { - $matches = true; + $matches = (count(explode('/', rtrim($url, '/'))) == count(explode('/', rtrim($route, '/')))); if($this->regexMatch) { $parameters = $this->parseParameters($url, true, $this->regexMatch); @@ -62,7 +62,7 @@ class RouterRoute extends RouterEntry { } else { $url = explode('/', $url); - $route = explode('/', $route); + $route = explode('/', rtrim($route, '/')); $parameters = array();