laravel/public/index.php

124 lines
4.1 KiB
PHP
Raw Normal View History

2011-06-08 23:45:08 -05:00
<?php
/**
* Laravel - A clean and classy framework for PHP web development.
*
* @package Laravel
2011-07-16 10:09:30 -05:00
* @version 1.2.1
2011-07-16 13:49:33 -05:00
* @author Taylor Otwell1
2011-06-08 23:45:08 -05:00
* @license MIT License
* @link http://laravel.com
*/
// --------------------------------------------------------------
// Define the framework paths.
// --------------------------------------------------------------
define('BASE_PATH', realpath('../').'/');
2011-06-08 23:45:08 -05:00
define('APP_PATH', realpath('../application').'/');
define('SYS_PATH', realpath('../system').'/');
2011-06-16 20:09:50 -05:00
define('PUBLIC_PATH', realpath(__DIR__.'/'));
define('PACKAGE_PATH', APP_PATH.'packages/');
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
// Define the PHP file extension.
// --------------------------------------------------------------
define('EXT', '.php');
// --------------------------------------------------------------
2011-07-13 22:27:14 -05:00
// Load the classes used by the auto-loader.
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
require SYS_PATH.'config'.EXT;
require SYS_PATH.'arr'.EXT;
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
// Register the auto-loader.
// --------------------------------------------------------------
spl_autoload_register(require SYS_PATH.'loader'.EXT);
// --------------------------------------------------------------
// Set the error reporting and display levels.
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'Off');
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
// Register the error handlers.
// --------------------------------------------------------------
set_exception_handler(function($e)
{
require_once SYS_PATH.'error'.EXT;
2011-06-08 23:45:08 -05:00
System\Error::handle($e);
});
set_error_handler(function($number, $error, $file, $line)
{
require_once SYS_PATH.'error'.EXT;
System\Error::handle(new ErrorException($error, $number, 0, $file, $line));
2011-06-08 23:45:08 -05:00
});
register_shutdown_function(function()
{
if ( ! is_null($error = error_get_last()))
{
require_once SYS_PATH.'error'.EXT;
System\Error::handle(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
2011-06-08 23:45:08 -05:00
}
});
// --------------------------------------------------------------
// Set the default timezone.
// --------------------------------------------------------------
date_default_timezone_set(System\Config::get('application.timezone'));
// --------------------------------------------------------------
// Load the session.
// --------------------------------------------------------------
if (System\Config::get('session.driver') != '')
{
2011-07-11 07:06:20 -07:00
System\Session::load(System\Cookie::get('laravel_session'));
2011-06-08 23:45:08 -05:00
}
// --------------------------------------------------------------
// Execute the global "before" filter.
// --------------------------------------------------------------
2011-06-28 23:26:42 -05:00
$response = System\Route\Filter::call('before', array(), true);
2011-06-08 23:45:08 -05:00
2011-07-10 23:40:05 -05:00
// ----------------------------------------------------------
// Execute the route function.
// ----------------------------------------------------------
2011-06-08 23:45:08 -05:00
if (is_null($response))
{
$route = System\Router::route(Request::method(), Request::uri());
$response = (is_null($route)) ? System\Response::make(View::make('error/404'), 404) : $route->call();
2011-06-08 23:45:08 -05:00
}
else
{
2011-06-14 17:27:11 -05:00
$response = System\Response::prepare($response);
2011-06-08 23:45:08 -05:00
}
// ----------------------------------------------------------
// Execute the global "after" filter.
// ----------------------------------------------------------
2011-06-28 23:26:42 -05:00
System\Route\Filter::call('after', array($response));
2011-06-08 23:45:08 -05:00
// ----------------------------------------------------------
// Stringify the response.
// ----------------------------------------------------------
$response->content = (string) $response->content;
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
// Close the session.
// --------------------------------------------------------------
if (System\Config::get('session.driver') != '')
{
System\Session::close();
}
// --------------------------------------------------------------
// Send the response to the browser.
// --------------------------------------------------------------
$response->send();