added support for route filter parameters.

This commit is contained in:
Taylor Otwell 2011-09-30 22:23:47 -05:00
parent 21592ec67f
commit dfe3a04651
2 changed files with 14 additions and 2 deletions

View File

@ -134,7 +134,7 @@ protected function delegate(Route $route, $delegate)
// an underscore are not publicly available. // an underscore are not publicly available.
if (is_null($controller) or ($method == 'before' or strncmp($method, '_', 1) === 0)) if (is_null($controller) or ($method == 'before' or strncmp($method, '_', 1) === 0))
{ {
return $this->container->resolve('laravel.response')->error('404'); return Response::error('404');
} }
$controller->container = $this->container; $controller->container = $this->container;
@ -222,6 +222,16 @@ protected function filter($filters, $parameters = array(), $override = false)
{ {
foreach ((array) $filters as $filter) foreach ((array) $filters as $filter)
{ {
// Parameters may be passed into routes by specifying the list of parameters after
// a colon. If parameters are present, we will merge them into the parameter array
// that was passed to the method and slice the parameters off of the filter string.
if (($colon = strpos($filter, ':')) !== false)
{
$parameters = array_merge($parameters, explode(',', substr($filter, $colon + 1)));
$filter = substr($filter, 0, $colon);
}
if ( ! isset($this->filters[$filter])) continue; if ( ! isset($this->filters[$filter])) continue;
$response = call_user_func_array($this->filters[$filter], $parameters); $response = call_user_func_array($this->filters[$filter], $parameters);

View File

@ -126,7 +126,9 @@ public function filters($name)
{ {
if (is_array($this->callback) and isset($this->callback[$name])) if (is_array($this->callback) and isset($this->callback[$name]))
{ {
return explode(', ', $this->callback[$name]); $filters = $this->callback[$name];
return (is_string($filters)) ? explode('|', $filters) : $filters;
} }
return array(); return array();