From 8718b582df2a6e3b0af7162f63fd1ae985a177ff Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 9 Nov 2011 22:32:35 -0600 Subject: [PATCH] cleaning up the autoloader and core bootstrapping. --- laravel/autoloader.php | 14 -------------- laravel/bootstrap/core.php | 11 ++++------- laravel/laravel.php | 29 +++++++++++++---------------- laravel/routing/controller.php | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/laravel/autoloader.php b/laravel/autoloader.php index 65be66f1..8bb8428a 100644 --- a/laravel/autoloader.php +++ b/laravel/autoloader.php @@ -86,20 +86,6 @@ protected static function find($class) return $path; } - - // Since not all controllers will be resolved by the controller resolver, - // we will do a quick check in the controller directory for the class. - // For instance, since base controllers would not be resolved by the - // controller class, we will need to resolve them here. - if (strpos($class, '_Controller') !== false) - { - $controller = str_replace(array('_Controller', '_'), array('', '/'), $class); - - if (file_exists($path = strtolower(CONTROLLER_PATH.$controller.EXT))) - { - return $path; - } - } } } \ No newline at end of file diff --git a/laravel/bootstrap/core.php b/laravel/bootstrap/core.php index debdf36c..ef8fec89 100644 --- a/laravel/bootstrap/core.php +++ b/laravel/bootstrap/core.php @@ -1,10 +1,5 @@ core('session')->save($driver); } -/** - * Finally, we can send the response to the browser. - */ $response->send(); \ No newline at end of file diff --git a/laravel/routing/controller.php b/laravel/routing/controller.php index 065cc626..39130e93 100644 --- a/laravel/routing/controller.php +++ b/laravel/routing/controller.php @@ -6,6 +6,24 @@ use Laravel\Redirect; use Laravel\Response; +/** + * Register a function on the autoload stack to lazy-load controller files. + * We register this function here to keep the primary autoloader smaller + * since this logic is not needed for every Laravel application. + */ +spl_autoload_register(function($controller) +{ + if (strpos($controller, '_Controller') !== false) + { + $controller = str_replace(array('_Controller', '_'), array('', '/'), $controller); + + if (file_exists($path = strtolower(CONTROLLER_PATH.$controller.EXT))) + { + return $path; + } + } +}); + abstract class Controller { /**