working on routing architecture.

This commit is contained in:
Taylor Otwell
2011-07-31 21:51:55 -05:00
parent 344f49e1bf
commit 0af326b636
6 changed files with 59 additions and 22 deletions

View File

@@ -7,7 +7,28 @@ class Filter {
*
* @var array
*/
public static $filters;
private static $filters = array();
/**
* Register a set of route filters.
*
* @param array $filters
* @return void
*/
public static function register($filters)
{
static::$filters = array_merge(static::$filters, $filters);
}
/**
* Clear all of the registered route filters.
*
* @return void
*/
public static function clear()
{
static::$filters = array();
}
/**
* Call a set of route filters.
@@ -19,11 +40,6 @@ class Filter {
*/
public static function call($filters, $parameters = array(), $override = false)
{
if (is_null(static::$filters))
{
static::$filters = require APP_PATH.'filters'.EXT;
}
foreach (explode(', ', $filters) as $filter)
{
if ( ! isset(static::$filters[$filter]))
@@ -33,6 +49,9 @@ class Filter {
$response = call_user_func_array(static::$filters[$filter], $parameters);
// "Before" filters may override the request cycle. For example, an authentication
// filter may redirect a user to a login view if they are not logged in. Because of
// this, we will return the first filter response if overriding is enabled.
if ( ! is_null($response) and $override)
{
return $response;