Commit 2fae372c authored by Taylor Otwell's avatar Taylor Otwell

refactoring routing classes.

parent bae9553a
......@@ -62,8 +62,8 @@ class Caller {
{
// If a route returns a string, it also means the route is delegating the
// handling of the request to a controller method. So, we will pass the
// string to the route delegator, exploding on "::".
if (is_string($response)) $response = $this->delegate($route, explode('::', $response));
// string to the route delegator, exploding on "@".
if (is_string($response)) $response = $this->delegate($route, $response);
return $this->finish($route, $response);
}
......@@ -92,13 +92,13 @@ class Caller {
/**
* Handle the delegation of a route to a controller method.
*
* @param Route $route
* @param array $delegate
* @param Route $route
* @param string $delegate
* @return mixed
*/
protected function delegate(Route $route, $delegate)
{
list($controller, $method) = array($delegate[0], $delegate[1]);
list($controller, $method) = explode('@', $delegate);
$controller = $this->resolve($controller);
......
......@@ -67,7 +67,7 @@ class Route {
}
/**
* Call the route closure.
* Call the closure defined for the route, or get the route delegator.
*
* @return mixed
*/
......
......@@ -23,19 +23,19 @@ class Router {
*
* @var string
*/
protected $controller_path;
protected $controllers;
/**
* Create a new router for a request method and URI.
*
* @param array $routes
* @param string $controller_path
* @param string $controllers
* @return void
*/
public function __construct($routes, $controller_path)
public function __construct($routes, $controllers)
{
$this->routes = $routes;
$this->controller_path = $controller_path;
$this->controllers = $controllers;
}
/**
......@@ -121,7 +121,7 @@ class Router {
{
// If the request is to the root of the application, an ad-hoc route will be generated
// to the home controller's "index" method, making it the default controller method.
if ($request->uri() === '/') return new Route($request->method().' /', function() { return array('home', 'index'); });
if ($request->uri() === '/') return new Route($request->method().' /', 'home@index');
$segments = explode('/', trim($request->uri(), '/'));
......@@ -142,12 +142,7 @@ class Router {
// be used as the default controller method.
$method = (count($segments) > 0) ? array_shift($segments) : 'index';
// Now we're ready to dummy up a controller delegating route callback. This
// callback will look exactly like the callback the developer would create
// were they to code the controller delegation manually.
$callback = function() use ($controller, $method) { return array($controller, $method); };
return new Route($destination, $callback, $segments);
return new Route($destination, $controller.'@'.$method, $segments);
}
}
......@@ -167,7 +162,7 @@ class Router {
{
foreach (array_reverse($segments, true) as $key => $value)
{
if (file_exists($path = $this->controller_path.implode('/', array_slice($segments, 0, $key + 1)).EXT))
if (file_exists($path = $this->controllers.implode('/', array_slice($segments, 0, $key + 1)).EXT))
{
return $key + 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment