cleaning up the autoloader and core bootstrapping.

This commit is contained in:
Taylor Otwell 2011-11-09 22:32:35 -06:00
parent 56daba42c5
commit 8718b582df
4 changed files with 35 additions and 37 deletions

View File

@ -86,20 +86,6 @@ protected static function find($class)
return $path; 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;
}
}
} }
} }

View File

@ -1,10 +1,5 @@
<?php namespace Laravel; <?php namespace Laravel;
/**
* Define all of the constants used by the framework. All of the core
* paths will be defined, as well as all of the paths which derive
* from these core paths.
*/
define('EXT', '.php'); define('EXT', '.php');
define('CRLF', chr(13).chr(10)); define('CRLF', chr(13).chr(10));
define('BLADE_EXT', '.blade.php'); define('BLADE_EXT', '.blade.php');
@ -30,8 +25,10 @@
/** /**
* Define the Laravel environment configuration path. This path is used * Define the Laravel environment configuration path. This path is used
* by the configuration class to load configuration options specific * by the configuration class to load configuration options specific for
* for the server environment. * the server environment, allowing the developer to conveniently change
* configuration options based on the application environment.
*
*/ */
$environment = ''; $environment = '';

View File

@ -8,15 +8,12 @@
require 'bootstrap/core.php'; require 'bootstrap/core.php';
/** /**
* Register the framework error handling methods and set the * Register the framework error handling methods and set the error
* error_reporting levels. This file will register handlers * reporting levels. This file will register handlers for exceptions,
* for exceptions, errors, and shutdown. * errors, and the shutdown event.
*/ */
require SYS_PATH.'bootstrap/errors'.EXT; require SYS_PATH.'bootstrap/errors'.EXT;
/**
* Set the application's default timezone.
*/
date_default_timezone_set(Config::$items['application']['timezone']); date_default_timezone_set(Config::$items['application']['timezone']);
/** /**
@ -34,8 +31,9 @@
} }
/** /**
* Manually load some core classes that are used on every request * Manually load some core classes that are used on every request so
* This allows to avoid using the loader for these classes. * we can avoid using the loader for these classes. This saves us
* some overhead on each request.
*/ */
require SYS_PATH.'input'.EXT; require SYS_PATH.'input'.EXT;
require SYS_PATH.'request'.EXT; require SYS_PATH.'request'.EXT;
@ -46,9 +44,9 @@
require SYS_PATH.'routing/filter'.EXT; require SYS_PATH.'routing/filter'.EXT;
/** /**
* Gather the input to the application for the current request. * Gather the input to the application based on the current request.
* The input will be gathered based on the current request method * The input will be gathered based on the current request method and
* and will be set on the Input manager. * will be set on the Input manager.
*/ */
$input = array(); $input = array();
@ -75,8 +73,10 @@
} }
/** /**
* The spoofed request method is removed from the input so it is * The spoofed request method is removed from the input so it is not
* not unexpectedly included in Input::all() or Input::get(). * unexpectedly included in Input::all() or Input::get(). Leaving it
* in the input array could cause unexpected results if the developer
* fills an Eloquent model with the input.
*/ */
unset($input[Request::spoofer]); unset($input[Request::spoofer]);
@ -122,7 +122,4 @@
IoC::container()->core('session')->save($driver); IoC::container()->core('session')->save($driver);
} }
/**
* Finally, we can send the response to the browser.
*/
$response->send(); $response->send();

View File

@ -6,6 +6,24 @@
use Laravel\Redirect; use Laravel\Redirect;
use Laravel\Response; 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 { abstract class Controller {
/** /**