From e70261e962da5b570674329620c1338a210a2b05 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Feb 2012 15:09:04 -0600 Subject: [PATCH] added support for controller factories. --- laravel/event.php | 2 +- laravel/routing/controller.php | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/laravel/event.php b/laravel/event.php index 4ca96a77..418b82ed 100644 --- a/laravel/event.php +++ b/laravel/event.php @@ -83,7 +83,7 @@ public static function fire($event, $parameters = array()) { foreach (static::$events[$event] as $callback) { - $responses[] = call_user_func_array($callback, $parameters); + $responses[] = call_user_func_array($callback, (array) $parameters); } } diff --git a/laravel/routing/controller.php b/laravel/routing/controller.php index f8511b54..d6d3afe5 100644 --- a/laravel/routing/controller.php +++ b/laravel/routing/controller.php @@ -39,6 +39,13 @@ abstract class Controller { */ protected $filters = array(); + /** + * The event name for the Laravel controller factory. + * + * @var string + */ + const factory = 'laravel.controller.factory'; + /** * Call an action method on a controller. * @@ -127,12 +134,19 @@ public static function resolve($bundle, $controller) return IoC::resolve($resolver); } + $controller = static::format($bundle, $controller); + // If we couldn't resolve the controller out of the IoC container we'll // format the controller name into its proper class name and load it // by convention out of the bundle's controller directory. - $controller = static::format($bundle, $controller); - - $controller = new $controller; + if (Event::listeners(static::factory)) + { + $controller = Event::first(static::factory, $controller); + } + else + { + $controller = new $controller; + } // If the controller has specified a layout to be used when rendering // views, we will instantiate the layout instance and set it to the