diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index c5dbb35..35d33c4 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -91,7 +91,7 @@ class RouterBase { if($route instanceof RouterGroup && is_callable($route->getCallback())) { $group = $route; $route->renderRoute($this->request); - $mergedSettings = array_merge($route->getMergeableSettings(), $settings); + $mergedSettings = array_merge($settings, $route->getMergeableSettings()); } $this->currentRoute = null; @@ -373,7 +373,7 @@ class RouterBase { $route = $this->controllerUrlMap[$i]; // Check an alias exist, if the matches - use it - if($route instanceof RouterRoute && strtolower($route->getAlias()) === strtolower($controller)) { + if($route instanceof RouterRoute && $route->hasAlias($controller)) { return $this->processUrl($route, $route->getMethod(), $parameters, $getParams); } diff --git a/src/Pecee/SimpleRouter/RouterGroup.php b/src/Pecee/SimpleRouter/RouterGroup.php index 2283744..f3c0ed4 100644 --- a/src/Pecee/SimpleRouter/RouterGroup.php +++ b/src/Pecee/SimpleRouter/RouterGroup.php @@ -88,4 +88,18 @@ class RouterGroup extends RouterEntry { return $this->domain; } + /** + * @param array $settings + * @return self + */ + public function addSettings(array $settings = null) { + if(isset($settings['namespace'])) { + unset($settings['namespace']); + } + if(is_array($settings)) { + $this->settings = array_merge($this->settings, $settings); + } + return $this; + } + } \ No newline at end of file diff --git a/src/Pecee/SimpleRouter/RouterRoute.php b/src/Pecee/SimpleRouter/RouterRoute.php index 9b5fc7d..8b11afa 100644 --- a/src/Pecee/SimpleRouter/RouterRoute.php +++ b/src/Pecee/SimpleRouter/RouterRoute.php @@ -15,8 +15,6 @@ class RouterRoute extends RouterEntry { parent::__construct(); $this->setUrl($url); $this->setCallback($callback); - - $this->settings['aliases'] = array(); } public function matchRoute(Request $request) { @@ -50,8 +48,6 @@ class RouterRoute extends RouterEntry { return true; } - - return null; } @@ -88,15 +84,37 @@ class RouterRoute extends RouterEntry { /** * Get alias for the url which can be used when getting the url route. - * @return string + * @return string|array */ public function getAlias(){ return $this->alias; } + /** + * Check if route has given alias. + * + * @param $name + * @return bool + */ + public function hasAlias($name) { + if(is_array($this->alias)) { + foreach($this->alias as $alias) { + if(strtolower($alias) === strtolower($name)) { + return true; + } + } + } else { + if(strtolower($this->getAlias()) === strtolower($name)) { + return true; + } + } + + return false; + } + /** * Set the url alias for easier getting the url route. - * @param string $alias + * @param string|array $alias * @return self */ public function setAlias($alias){