Commit 01ddff5c authored by Taylor Otwell's avatar Taylor Otwell

adding support for filter patterns.

Signed-off-by: 's avatarTaylor Otwell <taylorotwell@gmail.com>
parent 99544821
...@@ -13,6 +13,13 @@ class Filter { ...@@ -13,6 +13,13 @@ class Filter {
*/ */
public static $filters = array(); public static $filters = array();
/**
* The route filters that are based on pattern.
*
* @var array
*/
public static $patterns = array();
/** /**
* All of the registered filter aliases. * All of the registered filter aliases.
* *
...@@ -39,7 +46,17 @@ class Filter { ...@@ -39,7 +46,17 @@ class Filter {
{ {
if (isset(static::$aliases[$name])) $name = static::$aliases[$name]; if (isset(static::$aliases[$name])) $name = static::$aliases[$name];
static::$filters[$name] = $callback; if (starts_with($name, 'pattern: '))
{
foreach (explode(', ', substr($name, 9)) as $pattern)
{
static::$patterns[$pattern] = $callback;
}
}
else
{
static::$filters[$name] = $callback;
}
} }
/** /**
......
...@@ -116,10 +116,13 @@ class URI { ...@@ -116,10 +116,13 @@ class URI {
* Determine if the current URI matches a given pattern. * Determine if the current URI matches a given pattern.
* *
* @param string $pattern * @param string $pattern
* @param string $uri
* @return bool * @return bool
*/ */
public static function is($pattern) public static function is($pattern, $uri = null)
{ {
$uri = $uri ?: static::current();
// Asterisks are translated into zero-or-more regular expression wildcards // Asterisks are translated into zero-or-more regular expression wildcards
// to make it convenient to check if the URI starts with a given pattern // to make it convenient to check if the URI starts with a given pattern
// such as "library/*". This is only done when not root. // such as "library/*". This is only done when not root.
...@@ -132,7 +135,7 @@ class URI { ...@@ -132,7 +135,7 @@ class URI {
$pattern = '^/$'; $pattern = '^/$';
} }
return preg_match('#'.$pattern.'#', static::current()); return preg_match('#'.$pattern.'#', $uri);
} }
/** /**
......
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