Refactor Router (remove getUri method. All logic moved to getRoute method). Modified RouterTest.
This commit is contained in:
@ -57,18 +57,29 @@ class Router
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $name
|
||||
* @return Route
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function getRoute()
|
||||
public function getRoute($name = null)
|
||||
{
|
||||
return $this->route;
|
||||
if (is_null($name)) {
|
||||
return $this->route;
|
||||
} else {
|
||||
if ($this->routeIsExists($name)) {
|
||||
return $this->getRouteByName($name);
|
||||
} else {
|
||||
$btrace = debug_backtrace();
|
||||
throw new ErrorException('Unknown route name: "' . $name . '". ' . 'Call from "' . $btrace[0]['file'] . '" on line ' . $btrace[0]['line'] . '.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
protected function routeIsExists($name)
|
||||
public function routeIsExists($name)
|
||||
{
|
||||
return array_key_exists($name, $this->routes);
|
||||
}
|
||||
@ -81,24 +92,4 @@ class Router
|
||||
{
|
||||
return $this->routes[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $route_name
|
||||
* @return string
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function getUri($route_name = null)
|
||||
{
|
||||
if (is_null($route_name)) {
|
||||
$route = $this->getRoute();
|
||||
} else {
|
||||
if ($this->routeIsExists($route_name)) {
|
||||
$route = $this->getRouteByName($route_name);
|
||||
} else {
|
||||
$btrace = debug_backtrace();
|
||||
throw new ErrorException('Unknown route name: "' . $route_name . '". ' . 'Call from "' . $btrace[0]['file'] . '" on line ' . $btrace[0]['line'] . '.');
|
||||
}
|
||||
}
|
||||
return $route->getUri();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user