added dynamic Request::is_ method.. e.g. Request::is_login().

This commit is contained in:
Taylor Otwell
2011-06-18 12:00:52 -05:00
parent 7f06e0f4cd
commit a3a9368707
3 changed files with 56 additions and 38 deletions

View File

@@ -2,12 +2,19 @@
class Route {
/**
* The route key, including request method and URI.
*
* @var string
*/
public $key;
/**
* The route callback or array.
*
* @var mixed
*/
public $route;
public $callback;
/**
* The parameters that will passed to the route function.
@@ -19,13 +26,15 @@ class Route {
/**
* Create a new Route instance.
*
* @param mixed $route
* @param array $parameters
* @param string $key
* @param mixed $callback
* @param array $parameters
* @return void
*/
public function __construct($route, $parameters = array())
public function __construct($key, $callback, $parameters = array())
{
$this->route = $route;
$this->key = $key;
$this->callback = $callback;
$this->parameters = $parameters;
}
@@ -44,34 +53,34 @@ class Route {
// If the route value is just a function, all we have to do
// is execute the function! There are no filters to call.
// ------------------------------------------------------------
if (is_callable($this->route))
if (is_callable($this->callback))
{
$response = call_user_func_array($this->route, $this->parameters);
$response = call_user_func_array($this->callback, $this->parameters);
}
// ------------------------------------------------------------
// If the route value is an array, we'll need to check it for
// any filters that may be attached.
// ------------------------------------------------------------
elseif (is_array($this->route))
elseif (is_array($this->callback))
{
$response = isset($this->route['before']) ? Filter::call($this->route['before'], array(), true) : null;
$response = isset($this->callback['before']) ? Filter::call($this->callback['before'], array(), true) : null;
// ------------------------------------------------------------
// We verify that the before filters did not return a response
// Before filters can override the request cycle to make things
// like authentication convenient to implement.
// ------------------------------------------------------------
if (is_null($response) and isset($this->route['do']))
if (is_null($response) and isset($this->callback['do']))
{
$response = call_user_func_array($this->route['do'], $this->parameters);
$response = call_user_func_array($this->callback['do'], $this->parameters);
}
}
$response = Response::prepare($response);
if (is_array($this->route) and isset($this->route['after']))
if (is_array($this->callback) and isset($this->callback['after']))
{
Filter::call($this->route['after'], array($response));
Filter::call($this->callback['after'], array($response));
}
return $response;