adding support for attaching filters based on URI routing.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php namespace Laravel\Routing;
|
||||
|
||||
use Closure;
|
||||
use Laravel\URI;
|
||||
use Laravel\Bundle;
|
||||
use Laravel\Request;
|
||||
use Laravel\Response;
|
||||
@@ -172,9 +173,38 @@ class Route {
|
||||
$filters = array_merge($filters, $assigned);
|
||||
}
|
||||
|
||||
// Next we will attach any pattern type filters to the array of
|
||||
// filters as these are matched to the route by the route's
|
||||
// URI and not explicitly attached to routes.
|
||||
if ($event == 'before')
|
||||
{
|
||||
$filters = array_merge($filters, $this->patterns());
|
||||
}
|
||||
|
||||
return array(new Filter_Collection($filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pattern filters for the route.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function patterns()
|
||||
{
|
||||
// We will simply iterate through the registered patterns and
|
||||
// check the URI pattern against the URI for the route and
|
||||
// if they match we'll attach the filter.
|
||||
foreach (Filter::$patterns as $pattern => $filter)
|
||||
{
|
||||
if (URI::is($pattern, $this->uri))
|
||||
{
|
||||
$filters[] = $filter;
|
||||
}
|
||||
}
|
||||
|
||||
return (array) $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the controller action delegate assigned to the route.
|
||||
*
|
||||
@@ -340,11 +370,11 @@ class Route {
|
||||
/**
|
||||
* Register a route filter.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Closure $callback
|
||||
* @param string $name
|
||||
* @param mixed $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function filter($name, Closure $callback)
|
||||
public static function filter($name, $callback)
|
||||
{
|
||||
Filter::register($name, $callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user