From 01ddff5cdc3e0eab13e7fcd4a710e66735f672c1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 27 Feb 2012 22:36:28 -0600 Subject: [PATCH] adding support for filter patterns. Signed-off-by: Taylor Otwell --- laravel/routing/filter.php | 19 ++++++++++++++++++- laravel/uri.php | 7 +++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/laravel/routing/filter.php b/laravel/routing/filter.php index 61e3def2..e76fe961 100644 --- a/laravel/routing/filter.php +++ b/laravel/routing/filter.php @@ -13,6 +13,13 @@ class Filter { */ public static $filters = array(); + /** + * The route filters that are based on pattern. + * + * @var array + */ + public static $patterns = array(); + /** * All of the registered filter aliases. * @@ -39,7 +46,17 @@ public static function register($name, Closure $callback) { 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; + } } /** diff --git a/laravel/uri.php b/laravel/uri.php index b94c95e0..d342f565 100644 --- a/laravel/uri.php +++ b/laravel/uri.php @@ -116,10 +116,13 @@ protected static function format($uri) * Determine if the current URI matches a given pattern. * * @param string $pattern + * @param string $uri * @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 // to make it convenient to check if the URI starts with a given pattern // such as "library/*". This is only done when not root. @@ -132,7 +135,7 @@ public static function is($pattern) $pattern = '^/$'; } - return preg_match('#'.$pattern.'#', static::current()); + return preg_match('#'.$pattern.'#', $uri); } /**