From 3833e12c72c5077ab56e2ebf313c41b145b71cf2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 7 Nov 2011 22:48:17 -0600 Subject: [PATCH] added before and after filter methods to controller. --- laravel/routing/controller.php | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/laravel/routing/controller.php b/laravel/routing/controller.php index 563d56c4..596ce686 100644 --- a/laravel/routing/controller.php +++ b/laravel/routing/controller.php @@ -137,23 +137,55 @@ protected static function hidden($method) } /** - * Set filters on the controller's methods. + * Set "after" filters on the controller's methods. * * Generally, this method will be used in the controller's constructor. * * - * // Set an "auth" before filter on the controller - * $this->filter('before', 'auth'); + * // Set a "foo" before filter on the controller + * $this->before_filter('foo'); * * // Set several filters on an explicit group of methods - * $this->filter('before', 'auth|csrf')->only(array('user', 'profile')); + * $this->before_filter('foo|bar')->only(array('user', 'profile')); * * + * @param string|array $filters + * @return Filter_Collection + */ + public function before_filter($filters) + { + return $this->filter('before', $filters); + } + + /** + * Set "after" filters on the controller's methods. + * + * Generally, this method will be used in the controller's constructor. + * + * + * // Set a "foo" after filter on the controller + * $this->after_filter('foo'); + * + * // Set several filters on an explicit group of methods + * $this->after_filter('foo|bar')->only(array('user', 'profile')); + * + * + * @param string|array $filters + * @return Filter_Collection + */ + public function after_filter($filters) + { + return $this->filter('after', $filters); + } + + /** + * Set filters on the controller's methods. + * * @param string $name * @param string|array $filters * @return Filter_Collection */ - public function filter($name, $filters) + protected function filter($name, $filters) { $this->filters[] = new Filter_Collection($name, $filters);