various refactoring and tweaks.
This commit is contained in:
@@ -60,13 +60,11 @@ abstract class Controller {
|
||||
}
|
||||
|
||||
// The after filter and the framework expects all responses to
|
||||
// be instances of the Response class. If the route did not
|
||||
// be instances of the Response class. If the method did not
|
||||
// return an instsance of Response, we will make on now.
|
||||
if ( ! $response instanceof Response) $response = new Response($response);
|
||||
|
||||
$filters = array_merge($controller->filters('after'), array('after'));
|
||||
|
||||
Filter::run($filters, array($response));
|
||||
Filter::run($controller->filters('after'), array($response));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,12 @@ class Route {
|
||||
// Since "before" filters can halt the request cycle, we will return
|
||||
// any response from the before filters. Allowing filters to halt the
|
||||
// request cycle makes tasks like authorization convenient.
|
||||
//
|
||||
// The route is responsible for running the global filters, and any
|
||||
// filters defined on the route itself. Since all incoming requests
|
||||
// come through a route (either defined or ad-hoc), it makes sense
|
||||
// to let the route handle the global filters. If the route uses
|
||||
// a controller, the controller will only call its own filters.
|
||||
$before = array_merge(array('before'), $this->filters('before'));
|
||||
|
||||
if ( ! is_null($response = Filter::run($before, array(), true)))
|
||||
@@ -104,21 +110,22 @@ class Route {
|
||||
{
|
||||
if ($response instanceof Delegate)
|
||||
{
|
||||
return Controller::call($response->destination, $this->parameters);
|
||||
$response = Controller::call($response->destination, $this->parameters);
|
||||
}
|
||||
else
|
||||
|
||||
// The after filter and the framework expects all responses to
|
||||
// be instances of the Response class. If the route did not
|
||||
// return an instsance of Response, we will make on now.
|
||||
if ( ! $response instanceof Response)
|
||||
{
|
||||
// The after filter and the framework expects all responses to
|
||||
// be instances of the Response class. If the route did not
|
||||
// return an instsance of Response, we will make on now.
|
||||
if ( ! $response instanceof Response) $response = new Response($response);
|
||||
|
||||
$filters = array_merge($this->filters('after'), array('after'));
|
||||
|
||||
Filter::run($filters, array($response));
|
||||
|
||||
return $response;
|
||||
$response = new Response($response);
|
||||
}
|
||||
|
||||
$filters = array_merge($this->filters('after'), array('after'));
|
||||
|
||||
Filter::run($filters, array($response));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
return Response::error('404');
|
||||
|
||||
@@ -153,7 +153,10 @@ class Router {
|
||||
foreach (explode(', ', $keys) as $key)
|
||||
{
|
||||
// Append the provided formats to the route as an optional regular expression.
|
||||
if ( ! is_null($formats = $this->provides($callback))) $key .= '(\.('.implode('|', $formats).'))?';
|
||||
if ( ! is_null($formats = $this->provides($callback)))
|
||||
{
|
||||
$key .= '(\.('.implode('|', $formats).'))?';
|
||||
}
|
||||
|
||||
if (preg_match('#^'.$this->wildcards($key).'$#', $destination))
|
||||
{
|
||||
@@ -216,7 +219,9 @@ class Router {
|
||||
{
|
||||
foreach (array_reverse($segments, true) as $key => $value)
|
||||
{
|
||||
if (file_exists($path = $this->controllers.implode('/', array_slice($segments, 0, $key + 1)).EXT))
|
||||
$controller = implode('/', array_slice($segments, 0, $key + 1)).EXT;
|
||||
|
||||
if (file_exists($path = $this->controllers.$controller))
|
||||
{
|
||||
return $key + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user