[FEATURE] Added support for multiple aliases

This commit is contained in:
Simon Sessingø
2016-04-07 19:33:04 +02:00
parent 6e102711a8
commit 27371dfa11
2 changed files with 25 additions and 7 deletions
+1 -1
View File
@@ -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);
}
+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){