merged skunkworks into develop.

This commit is contained in:
Taylor Otwell
2012-01-16 13:59:24 -06:00
parent 610d8827c4
commit b5442c67fc
117 changed files with 7268 additions and 3999 deletions

View File

@@ -1,61 +1,26 @@
<?php namespace Laravel;
/**
* Bootstrap the core framework components like the IoC container,
* configuration class, and the class auto-loader. Once this file
* Bootstrap the core framework components like the IoC container and
* the configuration class, and the class auto-loader. Once this file
* has run, the framework is essentially ready for use.
*/
require 'core.php';
/**
* Create the exception logging function. All of the error logging
* is routed through here to avoid duplicate code. This Closure
* will determine if the actual logging Closure should be called.
* Register the default timezone for the application. This will be the
* default timezone used by all date / timezone functions throughout
* the entire application.
*/
$logger = function($exception)
{
if (Config::$items['error']['log'])
{
call_user_func(Config::$items['error']['logger'], $exception);
}
};
/**
* Create the exception handler function. All of the error handlers
* registered by the framework call this closure to avoid duplicate
* code. This Closure will pass the exception to the developer
* defined handler in the configuration file.
*/
$handler = function($exception) use ($logger)
{
$logger($exception);
if (Config::$items['error']['detail'])
{
echo "<html><h2>Unhandled Exception</h2>
<h3>Message:</h3>
<pre>".$exception->getMessage()."</pre>
<h3>Location:</h3>
<pre>".$exception->getFile()." on line ".$exception->getLine()."</pre>
<h3>Stack Trace:</h3>
<pre>".$exception->getTraceAsString()."</pre></html>";
}
else
{
Response::error('500')->send();
}
exit(1);
};
date_default_timezone_set(Config::get('application.timezone'));
/**
* Register the PHP exception handler. The framework throws exceptions
* on every error that cannot be handled. All of those exceptions will
* be sent through this closure for processing.
*/
set_exception_handler(function($exception) use ($handler)
set_exception_handler(function($e)
{
$handler($exception);
Error::exception($e);
});
/**
@@ -65,18 +30,9 @@ set_exception_handler(function($exception) use ($handler)
* errors are ignored and errors in the developer configured whitelist
* are silently logged.
*/
set_error_handler(function($code, $error, $file, $line) use ($logger)
set_error_handler(function($code, $error, $file, $line)
{
if (error_reporting() === 0) return;
$exception = new \ErrorException($error, $code, 0, $file, $line);
if (in_array($code, Config::$items['error']['ignore']))
{
return $logger($exception);
}
throw $exception;
Error::native($code, $error, $file, $line);
});
/**
@@ -85,14 +41,9 @@ set_error_handler(function($code, $error, $file, $line) use ($logger)
* has occured, we will convert it to an ErrorException and pass it
* to the common exception handler for the framework.
*/
register_shutdown_function(function() use ($handler)
register_shutdown_function(function()
{
if ( ! is_null($error = error_get_last()))
{
extract($error, EXTR_SKIP);
$handler(new \ErrorException($message, $type, 0, $file, $line));
}
Error::shutdown();
});
/**
@@ -114,21 +65,17 @@ ini_set('display_errors', 'Off');
* payload will be registered in the IoC container as an instance
* so it can be retrieved easily throughout the application.
*/
if (Config::$items['session']['driver'] !== '')
if (Config::get('session.driver') !== '')
{
$driver = Session\Drivers\Factory::make(Config::$items['session']['driver']);
Session::start(Config::get('session.driver'));
$session = new Session\Payload($driver);
$session->load(Cookie::get(Config::$items['session']['cookie']));
IoC::instance('laravel.session', $session);
Session::load(Cookie::get(Config::get('session.cookie')));
}
/**
* Gather the input to the application based on the current request.
* The input will be gathered based on the current request method and
* will be set on the Input manager.
* The input will be gathered based on the current request method
* and will be set on the Input manager.
*/
$input = array();
@@ -157,28 +104,55 @@ switch (Request::method())
/**
* The spoofed request method is removed from the input so it is not
* 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.
* in the input array could cause unexpected results if an Eloquent
* model is filled with the input.
*/
unset($input[Request::spoofer]);
Input::$input = $input;
/**
* Start all of the bundles that are specified in the configuration
* array of auto-loaded bundles. This gives the developer the ability
* to conveniently and automatically load bundles that are used on
* every request to their application.
*/
foreach (Config::get('application.bundles') as $bundle)
{
Bundle::start($bundle);
}
/**
* Load the "application" bundle. Though the application folder is
* not typically considered a bundle, it is started like one and
* essentially serves as the "default" bundle.
*/
Bundle::start(DEFAULT_BUNDLE);
/**
* If the first segment of the request URI corresponds with a bundle,
* we will start that bundle. By convention, bundles handle all URIs
* which begin with their bundle name.
*/
$bundle = URI::segment(1);
if ( ! is_null($bundle) and Bundle::routable($bundle))
{
Bundle::start($bundle);
}
/**
* Route the request to the proper route in the application. If a
* route is found, the route will be called with the current request
* instance. If no route is found, the 404 response will be returned
* to the browser.
*/
Routing\Filter::register(require APP_PATH.'filters'.EXT);
if (count(URI::$segments) > 15)
{
throw new \Exception("Invalid request. Too many URI segments.");
}
$loader = new Routing\Loader(APP_PATH, ROUTE_PATH);
$router = new Routing\Router($loader, CONTROLLER_PATH);
IoC::instance('laravel.routing.router', $router);
Request::$route = $router->route(Request::method(), URI::current());
Request::$route = Routing\Router::route(Request::method(), URI::current());
if ( ! is_null(Request::$route))
{
@@ -195,9 +169,9 @@ else
* driver is a sweeper, session garbage collection might be
* performed depending on the "sweepage" probability.
*/
if (Config::$items['session']['driver'] !== '')
if (Config::get('session.driver') !== '')
{
IoC::core('session')->save();
Session::save();
}
$response->send();