Commit ebc73681 authored by Taylor Otwell's avatar Taylor Otwell

Refactor the laravel.php bootstrap.

parent 4326f959
...@@ -104,11 +104,6 @@ require SYS_PATH.'routing/router'.EXT; ...@@ -104,11 +104,6 @@ require SYS_PATH.'routing/router'.EXT;
require SYS_PATH.'routing/loader'.EXT; require SYS_PATH.'routing/loader'.EXT;
require SYS_PATH.'routing/filter'.EXT; require SYS_PATH.'routing/filter'.EXT;
// --------------------------------------------------------------
// Register the route filters.
// --------------------------------------------------------------
Routing\Filter::register(require APP_PATH.'filters'.EXT);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Load the packages that are in the auto-loaded packages array. // Load the packages that are in the auto-loaded packages array.
// -------------------------------------------------------------- // --------------------------------------------------------------
...@@ -120,46 +115,57 @@ if (count(Config::get('application.packages')) > 0) ...@@ -120,46 +115,57 @@ if (count(Config::get('application.packages')) > 0)
} }
// -------------------------------------------------------------- // --------------------------------------------------------------
// Execute the global "before" filter. // Register the application filters.
// -------------------------------------------------------------- // --------------------------------------------------------------
$response = Routing\Filter::call('before', array(), true); Routing\Filter::register(require APP_PATH.'filters'.EXT);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Route the request and call the appropriate route function. // Determine the module that should handle the request.
// -------------------------------------------------------------- // --------------------------------------------------------------
if (is_null($response)) $segments = explode('/', Request::uri());
{
if (in_array($module = Request::segment(1), Config::get('application.modules')))
{
define('ACTIVE_MODULE', $module);
$path = MODULE_PATH.$module.'/'; define('ACTIVE_MODULE', (in_array($segments[0], Config::get('application.modules'))) ? $segments[0] : 'application');
if (file_exists($filters = $path.'filters'.EXT)) // --------------------------------------------------------------
{ // Determine the path to the root of the active module.
Routing\Filter::register(require $filters); // --------------------------------------------------------------
} define('ACTIVE_MODULE_PATH', (ACTIVE_MODULE == 'application') ? APP_PATH : MODULE_PATH.ACTIVE_MODULE.'/');
}
else
{
define('ACTIVE_MODULE', 'application');
$path = APP_PATH;
}
$route = Routing\Router::make(Request::method(), Request::uri(), new Routing\Loader($path))->route(); // --------------------------------------------------------------
// Register the filters for the active module.
// --------------------------------------------------------------
if (ACTIVE_MODULE !== 'application' and file_exists($filters = ACTIVE_MODULE_PATH.'filters'.EXT))
{
Routing\Filter::register(require $filters);
}
$response = (is_null($route)) ? Response::error('404') : $route->call(); // --------------------------------------------------------------
// Call the "before" filter for the application and module.
// --------------------------------------------------------------
foreach (array('before', ACTIVE_MODULE.'::before') as $filter)
{
$response = Routing\Filter::call($filter, array(), true);
} }
else
// --------------------------------------------------------------
// Route the request and get the response from the route.
// --------------------------------------------------------------
if (is_null($response))
{ {
$response = Response::prepare($response); $route = Routing\Router::make(Request::method(), Request::uri(), new Routing\Loader(ACTIVE_MODULE_PATH))->route();
$response = (is_null($route)) ? Response::error('404') : $route->call();
} }
$response = Response::prepare($response);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Execute the global "after" filter. // Call the "after" filter for the application and module.
// -------------------------------------------------------------- // --------------------------------------------------------------
Routing\Filter::call('after', array($response)); foreach (array(ACTIVE_MODULE.'::after', 'after') as $filter)
{
Routing\Filter::call($filter, array($response));
}
// -------------------------------------------------------------- // --------------------------------------------------------------
// Stringify the response. // Stringify the response.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment