Files
spa-api/laravel/laravel.php

177 lines
4.7 KiB
PHP
Raw Normal View History

2011-08-18 19:56:29 -05:00
<?php namespace Laravel;
2011-09-22 00:09:53 -05:00
/**
2012-01-16 13:59:24 -06:00
* Bootstrap the core framework components like the IoC container and
* the configuration class, and the class auto-loader. Once this file
2011-09-29 21:22:48 -05:00
* has run, the framework is essentially ready for use.
2011-09-22 00:09:53 -05:00
*/
2011-11-22 18:00:17 -06:00
require 'core.php';
2011-11-10 22:46:01 -06:00
/**
2012-01-16 13:59:24 -06:00
* Register the default timezone for the application. This will be the
* default timezone used by all date / timezone functions throughout
* the entire application.
2011-11-10 22:46:01 -06:00
*/
2012-01-16 13:59:24 -06:00
date_default_timezone_set(Config::get('application.timezone'));
2011-11-10 22:46:01 -06:00
/**
* 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.
*/
2012-01-16 13:59:24 -06:00
set_exception_handler(function($e)
2011-11-10 22:46:01 -06:00
{
2012-01-16 13:59:24 -06:00
Error::exception($e);
2011-11-10 22:46:01 -06:00
});
/**
* Register the PHP error handler. All PHP errors will fall into this
* handler, which will convert the error into an ErrorException object
* and pass the exception into the common exception handler. Suppressed
* errors are ignored and errors in the developer configured whitelist
* are silently logged.
2011-11-10 22:46:01 -06:00
*/
2012-01-16 13:59:24 -06:00
set_error_handler(function($code, $error, $file, $line)
2011-11-10 22:46:01 -06:00
{
2012-01-16 13:59:24 -06:00
Error::native($code, $error, $file, $line);
2011-11-10 22:46:01 -06:00
});
/**
* Register the PHP shutdown handler. This function will be called
* at the end of the PHP script or on a fatal PHP error. If an error
* has occured, we will convert it to an ErrorException and pass it
* to the common exception handler for the framework.
*/
2012-01-16 13:59:24 -06:00
register_shutdown_function(function()
2011-11-10 22:46:01 -06:00
{
2012-01-16 13:59:24 -06:00
Error::shutdown();
2011-11-10 22:46:01 -06:00
});
/**
* Setting the PHP error reporting level to -1 essentially forces
* PHP to report every error, and is guranteed to show every error
* on future versions of PHP.
2011-11-14 21:18:18 -06:00
*
2011-11-10 22:46:01 -06:00
* If error detail is turned off, we will turn off all PHP error
* reporting and display since the framework will be displaying a
* generic message and we don't want any sensitive details about
* the exception leaking into the views.
*/
2011-11-14 21:18:18 -06:00
error_reporting(-1);
ini_set('display_errors', 'Off');
2011-11-10 22:46:01 -06:00
2011-09-22 00:09:53 -05:00
/**
2011-09-29 21:22:48 -05:00
* Load the session and session manager instance. The session
* payload will be registered in the IoC container as an instance
* so it can be retrieved easily throughout the application.
2011-09-22 00:09:53 -05:00
*/
2012-01-16 13:59:24 -06:00
if (Config::get('session.driver') !== '')
2011-08-26 21:42:04 -05:00
{
2012-01-16 13:59:24 -06:00
Session::start(Config::get('session.driver'));
2011-11-22 07:47:21 -06:00
2012-01-16 13:59:24 -06:00
Session::load(Cookie::get(Config::get('session.cookie')));
2011-09-08 17:49:16 -05:00
}
2011-08-26 21:42:04 -05:00
2011-10-29 22:31:50 -05:00
/**
* Gather the input to the application based on the current request.
2012-01-16 13:59:24 -06:00
* The input will be gathered based on the current request method
* and will be set on the Input manager.
2011-10-29 22:31:50 -05:00
*/
$input = array();
switch (Request::method())
{
case 'GET':
$input = $_GET;
break;
case 'POST':
$input = $_POST;
break;
case 'PUT':
case 'DELETE':
if (Request::spoofed())
{
$input = $_POST;
}
else
{
parse_str(file_get_contents('php://input'), $input);
}
}
/**
* The spoofed request method is removed from the input so it is not
* unexpectedly included in Input::all() or Input::get(). Leaving it
2012-01-16 13:59:24 -06:00
* in the input array could cause unexpected results if an Eloquent
* model is filled with the input.
2011-10-29 22:31:50 -05:00
*/
unset($input[Request::spoofer]);
Input::$input = $input;
2012-01-16 13:59:24 -06:00
/**
* 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);
}
2011-10-05 18:32:48 -05:00
/**
* 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.
*/
2012-01-16 13:59:24 -06:00
if (count(URI::$segments) > 15)
{
throw new \Exception("Invalid request. Too many URI segments.");
}
2011-11-11 23:36:31 -06:00
2012-01-16 13:59:24 -06:00
Request::$route = Routing\Router::route(Request::method(), URI::current());
2011-08-26 21:42:04 -05:00
2011-10-29 22:31:50 -05:00
if ( ! is_null(Request::$route))
2011-08-26 21:42:04 -05:00
{
2011-10-29 22:31:50 -05:00
$response = Request::$route->call();
2011-08-26 21:42:04 -05:00
}
else
{
$response = Response::error('404');
2011-08-26 21:42:04 -05:00
}
2011-09-22 00:09:53 -05:00
/**
2011-09-29 21:22:48 -05:00
* Close the session and write the active payload to persistent
2011-10-31 22:15:47 -05:00
* storage. The session cookie will also be written and if the
* driver is a sweeper, session garbage collection might be
* performed depending on the "sweepage" probability.
2011-09-22 00:09:53 -05:00
*/
2012-01-16 13:59:24 -06:00
if (Config::get('session.driver') !== '')
2011-08-19 20:12:39 -05:00
{
2012-01-16 13:59:24 -06:00
Session::save();
2011-08-19 20:12:39 -05:00
}
2011-11-21 21:57:11 -06:00
$response->send();