Clean up the life-cycle file.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
@@ -1,61 +1,70 @@
|
|||||||
<?php namespace Laravel;
|
<?php namespace Laravel;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Bootstrap the core framework components like the IoC container and
|
|--------------------------------------------------------------------------
|
||||||
* the configuration class, and the class auto-loader. Once this file
|
| Bootstrap The Framework Core
|
||||||
* has run, the framework is essentially ready for use.
|
|--------------------------------------------------------------------------
|
||||||
*/
|
|
|
||||||
|
| By including this file, the core of the framework will be setup which
|
||||||
|
| includes the class auto-loader, and the registration of any bundles.
|
||||||
|
| Basically, once this file has been included, the entire framework
|
||||||
|
| may be used by the developer.
|
||||||
|
|
|
||||||
|
*/
|
||||||
require 'core.php';
|
require 'core.php';
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Register the PHP exception handler. The framework throws exceptions
|
|--------------------------------------------------------------------------
|
||||||
* on every error that cannot be handled. All of those exceptions will
|
| Setup Error & Exception Handling
|
||||||
* be sent through this closure for processing.
|
|--------------------------------------------------------------------------
|
||||||
*/
|
|
|
||||||
|
| Next we'll register custom handlers for all errors and exceptions so we
|
||||||
|
| can display a clean error message for all errors, as well as do any
|
||||||
|
| custom error logging that may be setup by the developer.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
set_exception_handler(function($e)
|
set_exception_handler(function($e)
|
||||||
{
|
{
|
||||||
Error::exception($e);
|
Error::exception($e);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 exception handler.
|
|
||||||
*/
|
|
||||||
set_error_handler(function($code, $error, $file, $line)
|
set_error_handler(function($code, $error, $file, $line)
|
||||||
{
|
{
|
||||||
Error::native($code, $error, $file, $line);
|
Error::native($code, $error, $file, $line);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the shutdown handler. This function will be called at the
|
|
||||||
* end of the PHP script or on a fatal PHP error. If a PHP error has
|
|
||||||
* occured, we will convert it to an ErrorException and pass it
|
|
||||||
* to the common exception handler for the framework.
|
|
||||||
*/
|
|
||||||
register_shutdown_function(function()
|
register_shutdown_function(function()
|
||||||
{
|
{
|
||||||
Error::shutdown();
|
Error::shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Setting the PHP error reporting level to -1 essentially forces
|
|--------------------------------------------------------------------------
|
||||||
* PHP to report every error, and it is guranteed to show every
|
| Report All Errors
|
||||||
* error on future versions of PHP.
|
|--------------------------------------------------------------------------
|
||||||
*
|
|
|
||||||
* If error detail is turned off, we will turn off all PHP error
|
| By setting error reporting to -1, we essentially force PHP to report
|
||||||
* reporting and display since the framework will be displaying
|
| every error, and this is guranteed to show every error on future
|
||||||
* a generic message and we do not want any sensitive details
|
| releases of PHP. This allows everything to be fixed early!
|
||||||
* about the exception leaking into the views.
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
error_reporting(-1);
|
error_reporting(-1);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Even though "Magic Quotes" are deprecated in PHP 5.3, they may
|
|--------------------------------------------------------------------------
|
||||||
* still be enabled on the server. To account for this, we will
|
| Magic Quotes Strip Slashes
|
||||||
* strip slashes on all input arrays if magic quotes are turned
|
|--------------------------------------------------------------------------
|
||||||
* on for the server environment.
|
|
|
||||||
*/
|
| Even though "Magic Quotes" are deprecated in PHP 5.3.x, they may still
|
||||||
|
| be enabled on the server. To account for this, we will strip slashes
|
||||||
|
| on all input arrays if magic quotes are enabled for the server.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
if (magic_quotes())
|
if (magic_quotes())
|
||||||
{
|
{
|
||||||
$magics = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
|
$magics = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
|
||||||
@@ -66,12 +75,18 @@ if (magic_quotes())
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Gather the input to the application based on the global input
|
|--------------------------------------------------------------------------
|
||||||
* variables for the current request. The input will be gathered
|
| Sniff The Input For The Request
|
||||||
* based on the current request method and will be set on the
|
|--------------------------------------------------------------------------
|
||||||
* Input manager class' static $input property.
|
|
|
||||||
*/
|
| Next we'll gather the input to the application based on the global input
|
||||||
|
| variables for the current request. The input will be gathered based on
|
||||||
|
| the current request method and will be set on the Input manager class
|
||||||
|
| as a simple static $input property which can be easily accessed.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
$input = array();
|
$input = array();
|
||||||
|
|
||||||
switch (Request::method())
|
switch (Request::method())
|
||||||
@@ -97,90 +112,137 @@ 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
|
| Remove The Spoofer Input
|
||||||
* in the input array could cause unexpected results if an Eloquent
|
|--------------------------------------------------------------------------
|
||||||
* model is filled with the input.
|
|
|
||||||
*/
|
| The spoofed request method is removed from the input so it is not in
|
||||||
|
| the Input::all() or Input::get() results. Leaving it in the array
|
||||||
|
| could cause unexpected results since the developer won't be
|
||||||
|
| expecting it to be present.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
unset($input[Request::spoofer]);
|
unset($input[Request::spoofer]);
|
||||||
|
|
||||||
Input::$input = $input;
|
Input::$input = $input;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Load the "application" bundle. Though the application folder is
|
|--------------------------------------------------------------------------
|
||||||
* not typically considered a bundle, it is started like one and
|
| Start The Application Bundle
|
||||||
* essentially serves as the "default" bundle.
|
|--------------------------------------------------------------------------
|
||||||
*/
|
|
|
||||||
|
| The application "bundle" is the default bundle for the installation and
|
||||||
|
| we'll fire it up first. In this bundle's bootstrap, more configuration
|
||||||
|
| will take place and the developer can hook into some of the core
|
||||||
|
| framework events such as the configuration loader.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
Bundle::start(DEFAULT_BUNDLE);
|
Bundle::start(DEFAULT_BUNDLE);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Auto-start any bundles configured to start on every request.
|
|--------------------------------------------------------------------------
|
||||||
* This is especially useful for debug bundles or bundles that
|
| Auto-Start Other Bundles
|
||||||
* are used throughout the application.
|
|--------------------------------------------------------------------------
|
||||||
*/
|
|
|
||||||
|
| Bundles that are used throughout the application may be auto-started
|
||||||
|
| so they are immediately available on every request without needing
|
||||||
|
| to explicitly start them within the application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
foreach (Bundle::$bundles as $bundle => $config)
|
foreach (Bundle::$bundles as $bundle => $config)
|
||||||
{
|
{
|
||||||
if ($config['auto']) Bundle::start($bundle);
|
if ($config['auto']) Bundle::start($bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Register the "catch-all" route that handles 404 responses for
|
|--------------------------------------------------------------------------
|
||||||
* routes that can not be matched to any other route within the
|
| Register The Catch-All Route
|
||||||
* application. We'll just raise the 404 event.
|
|--------------------------------------------------------------------------
|
||||||
*/
|
|
|
||||||
|
| This route will catch all requests that do not hit another route in
|
||||||
|
| the application, and will raise the 404 error event so the error
|
||||||
|
| can be handled by the developer in their 404 event listener.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
Routing\Router::register('*', '(:all)', function()
|
Routing\Router::register('*', '(:all)', function()
|
||||||
{
|
{
|
||||||
return Event::first('404');
|
return Event::first('404');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* If the requset URI has too many segments, we will bomb out of
|
|--------------------------------------------------------------------------
|
||||||
* the request. This is too avoid potential DDoS attacks against
|
| Route The Incoming Request
|
||||||
* the framework by overloading the controller lookup method
|
|--------------------------------------------------------------------------
|
||||||
* with thousands of segments.
|
|
|
||||||
*/
|
| Phew! We can finally route the request to the appropriate route and
|
||||||
|
| execute the route to get the response. This will give an instance
|
||||||
|
| of the Response object that we can send back to the browser
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
$uri = URI::current();
|
$uri = URI::current();
|
||||||
|
|
||||||
if (count(URI::$segments) > 15)
|
|
||||||
{
|
|
||||||
throw new \Exception("Invalid request. Too many URI segments.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Route the request to the proper route in the application. If a
|
|
||||||
* route is found, the route will be called via the request class
|
|
||||||
* static property. If no route is found, the 404 response will
|
|
||||||
* be returned to the browser.
|
|
||||||
*/
|
|
||||||
Request::$route = Routing\Router::route(Request::method(), $uri);
|
Request::$route = Routing\Router::route(Request::method(), $uri);
|
||||||
|
|
||||||
$response = Request::$route->call();
|
$response = Request::$route->call();
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Close the session and write the active payload to persistent
|
|--------------------------------------------------------------------------
|
||||||
* storage. The session cookie will also be written and if the
|
| Persist The Session To Storage
|
||||||
* driver is a sweeper, session garbage collection might be
|
|--------------------------------------------------------------------------
|
||||||
* performed depending on the "sweepage" probability.
|
|
|
||||||
*/
|
| If a session driver has been configured, we will save the session to
|
||||||
|
| storage so it is avaiable for the next request. This will also set
|
||||||
|
| the session cookie in the cookie jar to be sent to the user.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
if (Config::get('session.driver') !== '')
|
if (Config::get('session.driver') !== '')
|
||||||
{
|
{
|
||||||
Session::save();
|
Session::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Send all of the cookies to the browser. The cookies are
|
|--------------------------------------------------------------------------
|
||||||
* stored in a "jar" until the end of a request, primarily
|
| Let's Eat Cookies
|
||||||
* to make testing the cookie functionality of the site
|
|--------------------------------------------------------------------------
|
||||||
* much easier since the jar can be inspected.
|
|
|
||||||
*/
|
| All cookies set during the request are actually stored in a cookie jar
|
||||||
|
| until the end of the request so they can be expected by unit tests or
|
||||||
|
| the developer. Here, we'll push them out to the browser.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
Cookie::send();
|
Cookie::send();
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Send the final response to the browser and fire the
|
|--------------------------------------------------------------------------
|
||||||
* final event indicating that the processing for the
|
| Send The Response To The Browser
|
||||||
* current request is completed.
|
|--------------------------------------------------------------------------
|
||||||
*/
|
|
|
||||||
|
| We'll send the response back to the browser here. This method will also
|
||||||
|
| send all of the response headers to the browser as well as the string
|
||||||
|
| content of the Response. This should make the view available to the
|
||||||
|
| browser and show something pretty to the user.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
$response->send();
|
$response->send();
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| And We're Done!
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Raise the "done" event so extra output can be attached to the response
|
||||||
|
| This allows the adding of debug toolbars, etc. to the view, or may be
|
||||||
|
| used to do some kind of logging by the application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
Event::fire('laravel.done');
|
Event::fire('laravel.done');
|
||||||
Reference in New Issue
Block a user