From dfe3a04651edba0a1f7695691128218d82356f35 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 30 Sep 2011 22:23:47 -0500 Subject: [PATCH] added support for route filter parameters. --- laravel/routing/caller.php | 12 +++++++++++- laravel/routing/route.php | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/laravel/routing/caller.php b/laravel/routing/caller.php index 9bcb68dc..a76c302f 100644 --- a/laravel/routing/caller.php +++ b/laravel/routing/caller.php @@ -134,7 +134,7 @@ protected function delegate(Route $route, $delegate) // an underscore are not publicly available. 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; @@ -222,6 +222,16 @@ protected function filter($filters, $parameters = array(), $override = false) { 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; $response = call_user_func_array($this->filters[$filter], $parameters); diff --git a/laravel/routing/route.php b/laravel/routing/route.php index b724cce9..b9a1f58e 100644 --- a/laravel/routing/route.php +++ b/laravel/routing/route.php @@ -126,7 +126,9 @@ public function filters($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();