From 59956d5fca02039df4649acb70901af74aa92935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 10 Dec 2015 04:12:44 +0100 Subject: [PATCH] [BUGFIX] Optimisations + bugfixes. --- src/Pecee/SimpleRouter/RouterBase.php | 4 +++- src/Pecee/SimpleRouter/RouterEntry.php | 5 +++-- src/Pecee/SimpleRouter/RouterRoute.php | 11 +++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index 7d0ea01..b3cf31d 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -80,11 +80,13 @@ class RouterBase { } $this->currentRoute = $route; + if($route instanceof RouterGroup && is_callable($route->getCallback())) { $route->renderRoute($this->request); $activeGroup = $route; - $mergedSettings = array_merge($settings, $route->getMergeableSettings()); + $mergedSettings = array_merge($route->getMergeableSettings(), $settings); } + $this->currentRoute = null; if(count($this->backstack)) { diff --git a/src/Pecee/SimpleRouter/RouterEntry.php b/src/Pecee/SimpleRouter/RouterEntry.php index ee7641b..934c270 100644 --- a/src/Pecee/SimpleRouter/RouterEntry.php +++ b/src/Pecee/SimpleRouter/RouterEntry.php @@ -136,7 +136,7 @@ abstract class RouterEntry { * @return mixed */ public function getParameters(){ - return $this->parameters; + return ($this->parameters === null) ? array() : $this->parameters; } /** @@ -254,7 +254,8 @@ abstract class RouterEntry { $parameterRegex = $this->parametersRegex[$parameter]; } - for($i = 0; $i < strlen($route); $i++) { + $routeLength = strlen($route); + for($i = 0; $i < $routeLength; $i++) { $character = $route[$i]; diff --git a/src/Pecee/SimpleRouter/RouterRoute.php b/src/Pecee/SimpleRouter/RouterRoute.php index 83d5359..5e6e34b 100644 --- a/src/Pecee/SimpleRouter/RouterRoute.php +++ b/src/Pecee/SimpleRouter/RouterRoute.php @@ -64,7 +64,6 @@ class RouterRoute extends RouterEntry { * @return self */ public function setUrl($url) { - $parameters = array(); $matches = array(); @@ -72,12 +71,12 @@ class RouterRoute extends RouterEntry { $parameters = $matches[1]; } - $max = count($parameters); - if($max) { - for($i = 0; $i < $max; $i++) { - $param = $parameters[$i]; - $this->parameters[$param] = ''; + if(count($parameters)) { + $tmp = array(); + foreach($parameters as $param) { + $tmp[$param] = ''; } + $this->parameters = $tmp; } $this->url = $url;