Merge pull request #78 from skipperbent/development

[BUGFIX] Fixed nested groups not merging settings to routes
This commit is contained in:
Simon Sessingø
2016-04-07 19:34:02 +02:00
3 changed files with 40 additions and 8 deletions
+2 -2
View File
@@ -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);
}
+14
View File
@@ -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;
}
}
+24 -6
View File
@@ -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){