Rearrange Route

This commit is contained in:
PJ Dietz 2015-02-21 09:52:23 -05:00
parent 259dd0baa1
commit b350693aca
1 changed files with 28 additions and 29 deletions

View File

@ -24,17 +24,28 @@ use pjdietz\WellRESTed\Routes\StaticRoute;
*/
class Router implements HandlerInterface
{
/** @var array Hash array HTTP verb => RouteTable */
private $routeTables;
/** @var array Hash array of status code => error handler */
private $errorHandlers;
/** @var array Hash array HTTP verb => RouteTable */
private $routeTables;
/** Create a new Router. */
public function __construct()
{
$this->routeTables = array();
$this->errorHandlers = array();
$this->routeTables = array();
}
/**
* Append a new route to the route table.
*
* @param HandlerInterface $route
* @param string $method HTTP Method; * for any
*/
public function addRoute(HandlerInterface $route, $method = "*")
{
$table = $this->getRouteTable($method);
$table->addRoute($route);
}
/**
@ -96,7 +107,7 @@ class Router implements HandlerInterface
}
return $response;
}
/**
* Prepare a response indicating a 404 Not Found error
*
@ -115,6 +126,14 @@ class Router implements HandlerInterface
return $response;
}
private function getRouteTable($method = "*")
{
if (!isset($this->routeTables[$method])) {
$this->routeTables[$method] = new RouteTable();
}
return $this->routeTables[$method];
}
private function getResponseFromRouteTables(RequestInterface $request, array $args = null)
{
$method = $request->getMethod();
@ -170,6 +189,10 @@ class Router implements HandlerInterface
return $response;
}
////////////////
// Deprecated //
////////////////
/**
* @deprecated Use {@see addRoute} instead.
* @see addRoute
@ -180,30 +203,6 @@ class Router implements HandlerInterface
trigger_error("Router::setPrefixRoute is deprecated. Use addRoute", E_USER_DEPRECATED);
}
/**
* Append a new route to the route table.
*
* @param HandlerInterface $route
* @param string $method HTTP Method; * for any
*/
public function addRoute(HandlerInterface $route, $method = "*")
{
$table = $this->getRouteTable($method);
$table->addRoute($route);
}
////////////////
// Deprecated //
////////////////
private function getRouteTable($method = "*")
{
if (!isset($this->routeTables[$method])) {
$this->routeTables[$method] = new RouteTable();
}
return $this->routeTables[$method];
}
/**
* @deprecated Use {@see addRoute} instead.
* @see addRoute