laravel/public/index.php

195 lines
6.8 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-31 17:24:43 -05:00
* @version 1.4.1
* @author Taylor Otwell
2011-07-25 23:32:25 -05:00
* @link http://laravel.com
2011-06-08 23:45:08 -05:00
*/
// --------------------------------------------------------------
// Get the framework start time.
// --------------------------------------------------------------
$start = microtime(true);
2011-08-01 17:58:20 -05:00
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
2011-07-28 08:46:39 -05:00
// The path to the application directory.
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
define('APP_PATH', realpath('../application').'/');
2011-07-28 08:46:39 -05:00
// --------------------------------------------------------------
// The path to the system directory.
// --------------------------------------------------------------
define('SYS_PATH', realpath($system = '../system').'/');
// --------------------------------------------------------------
// The path to the directory containing the system directory.
// --------------------------------------------------------------
define('BASE_PATH', realpath(str_replace('system', '', $system)).'/');
2011-07-26 17:01:59 -05:00
// --------------------------------------------------------------
// The path to the public directory.
// --------------------------------------------------------------
define('PUBLIC_PATH', realpath(__DIR__).'/');
2011-07-26 17:01:59 -05:00
// --------------------------------------------------------------
// Define various other framework paths.
// --------------------------------------------------------------
2011-07-28 08:46:39 -05:00
$constants = array(
'CACHE_PATH' => APP_PATH.'storage/cache/',
'CONFIG_PATH' => APP_PATH.'config/',
'DATABASE_PATH' => APP_PATH.'storage/db/',
'LANG_PATH' => APP_PATH.'lang/',
'LIBRARY_PATH' => APP_PATH.'libraries/',
'MODEL_PATH' => APP_PATH.'models/',
'PACKAGE_PATH' => APP_PATH.'packages/',
'ROUTE_PATH' => APP_PATH.'routes/',
'SCRIPT_PATH' => PUBLIC_PATH.'js/',
2011-07-28 08:46:39 -05:00
'SESSION_PATH' => APP_PATH.'storage/sessions/',
'STORAGE_PATH' => APP_PATH.'storage/',
'STYLE_PATH' => PUBLIC_PATH.'css/',
2011-07-28 08:46:39 -05:00
'VIEW_PATH' => APP_PATH.'views/',
);
foreach ($constants as $key => $value)
{
define($key, $value);
}
unset($constants, $system);
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
// --------------------------------------------------------------
2011-08-02 22:19:13 -05:00
require SYS_PATH.'loader'.EXT;
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.
// --------------------------------------------------------------
2011-08-02 22:19:13 -05:00
System\Loader::bootstrap();
spl_autoload_register(array('System\\Loader', 'load'));
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
// Register the framework starting time with the Benchmarker.
// --------------------------------------------------------------
System\Benchmark::$marks['laravel'] = $start;
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
// 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
}
2011-08-01 17:58:20 -05:00
// --------------------------------------------------------------
// Load all of the core routing classes.
// --------------------------------------------------------------
require SYS_PATH.'request'.EXT;
require SYS_PATH.'response'.EXT;
require SYS_PATH.'routing/route'.EXT;
require SYS_PATH.'routing/router'.EXT;
require SYS_PATH.'routing/loader'.EXT;
require SYS_PATH.'routing/filter'.EXT;
2011-08-02 22:29:48 -05:00
// --------------------------------------------------------------
// Load the packages that are in the auto-loaded packages array.
// --------------------------------------------------------------
require SYS_PATH.'package'.EXT;
2011-08-02 22:40:12 -05:00
System\Package::load(System\Config::get('package.autoload'));
2011-08-02 22:29:48 -05:00
2011-07-31 21:51:55 -05:00
// --------------------------------------------------------------
// Register the route filters.
// --------------------------------------------------------------
2011-08-03 08:44:43 -05:00
System\Routing\Filter::register(require APP_PATH.'filters'.EXT);
2011-07-31 21:51:55 -05:00
2011-06-08 23:45:08 -05:00
// --------------------------------------------------------------
// Execute the global "before" filter.
// --------------------------------------------------------------
$response = System\Routing\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))
{
2011-08-03 08:44:43 -05:00
$route = System\Routing\Router::make(System\Request::method(), System\Request::uri(), new System\Routing\Loader(APP_PATH))->route();
2011-06-08 23:45:08 -05:00
$response = (is_null($route)) ? System\Response::error('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.
// ----------------------------------------------------------
System\Routing\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();