From 32684fa12e28645295c106c2a28c16f8b0ec1742 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Nov 2011 23:36:31 -0600 Subject: [PATCH] fixed router ioc bug. --- laravel/laravel.php | 2 ++ laravel/routing/filter.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/laravel/laravel.php b/laravel/laravel.php index 971ae6a2..9a6740ba 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -177,6 +177,8 @@ $loader = new Routing\Loader(APP_PATH, ROUTE_PATH); $router = new Routing\Router($loader, CONTROLLER_PATH); +IoC::instance('laravel.routing.router', $router); + Request::$route = $router->route($method, $uri); if ( ! is_null(Request::$route)) diff --git a/laravel/routing/filter.php b/laravel/routing/filter.php index f4ad41d2..f0c788b2 100644 --- a/laravel/routing/filter.php +++ b/laravel/routing/filter.php @@ -1,5 +1,7 @@ methods) > 0 and ! in_array(strtolower(Request::method()), $this->methods)) + { + return false; + } + return true; } @@ -178,4 +192,28 @@ class Filter_Collection { return $this; } + /** + * Set the HTTP methods for which the filter applies. + * + * Since some filters, such as the CSRF filter, only make sense in a POST + * request context, this method allows you to limit which HTTP methods + * the filter will apply to. + * + * + * // Specify that a filter only applies on POST requests + * $this->filter('before', 'csrf')->on('post'); + * + * // Specify that a filter applies for multiple HTTP request methods + * $this->filter('before', 'csrf')->on(array('post', 'put')); + * + * + * @param array $methods + * @return Filter_Collection + */ + public function on($methods) + { + $this->methods = array_map('strtolower', (array) $methods); + return $this; + } + } \ No newline at end of file