index.php 4.12 KB
Newer Older
1 2 3 4 5
<?php
/**
 * Laravel - A clean and classy framework for PHP web development.
 *
 * @package  Laravel
6
 * @version  1.1.1
7 8 9 10 11 12 13 14
 * @author   Taylor Otwell
 * @license  MIT License
 * @link     http://laravel.com 
 */

// --------------------------------------------------------------
// Define the framework paths.
// --------------------------------------------------------------
15
define('BASE_PATH', realpath('../').'/');
16 17
define('APP_PATH', realpath('../application').'/');
define('SYS_PATH', realpath('../system').'/');
Michael Hasselbring committed
18
define('PUBLIC_PATH', realpath(__DIR__.'/'));
19
define('PACKAGE_PATH', APP_PATH.'packages/');
20 21 22 23 24 25 26

// --------------------------------------------------------------
// Define the PHP file extension.
// --------------------------------------------------------------
define('EXT', '.php');

// --------------------------------------------------------------
27
// Load the configuration class.
28 29
// --------------------------------------------------------------
require SYS_PATH.'config'.EXT;
30
require SYS_PATH.'arr'.EXT;
31 32 33 34 35 36 37

// --------------------------------------------------------------
// Register the auto-loader.
// --------------------------------------------------------------
spl_autoload_register(require SYS_PATH.'loader'.EXT);

// --------------------------------------------------------------
38
// Set the error reporting and display levels.
39
// --------------------------------------------------------------
40 41 42
error_reporting(E_ALL | E_STRICT);

ini_set('display_errors', 'Off');
43 44 45 46 47 48

// --------------------------------------------------------------
// Register the error handlers.
// --------------------------------------------------------------
set_exception_handler(function($e)
{
49
	require_once SYS_PATH.'error'.EXT;
50

51 52 53 54 55
	System\Error::handle($e);	
});

set_error_handler(function($number, $error, $file, $line) 
{
56
	require_once SYS_PATH.'error'.EXT;
57 58

	System\Error::handle(new ErrorException($error, $number, 0, $file, $line));
59 60 61 62 63 64
});

register_shutdown_function(function()
{
	if ( ! is_null($error = error_get_last()))
	{
65
		require_once SYS_PATH.'error'.EXT;
66 67
		
		System\Error::handle(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
68 69 70 71 72 73 74 75 76 77 78 79 80
	}	
});

// --------------------------------------------------------------
// Set the default timezone.
// --------------------------------------------------------------
date_default_timezone_set(System\Config::get('application.timezone'));

// --------------------------------------------------------------
// Load the session.
// --------------------------------------------------------------
if (System\Config::get('session.driver') != '')
{
81
	System\Session::load(System\Cookie::get('laravel_session'));
82 83 84 85 86
}

// --------------------------------------------------------------
// Execute the global "before" filter.
// --------------------------------------------------------------
87
$response = System\Route\Filter::call('before', array(), true);
88

89 90 91
// ----------------------------------------------------------
// Execute the route function.
// ----------------------------------------------------------
92 93 94 95 96 97 98 99 100 101
if (is_null($response))
{
	$route = System\Router::route(Request::method(), Request::uri());

	if ( ! is_null($route))
	{
		$response = $route->call();	
	}
	else
	{
102
		$response = System\Response::make(View::make('error/404'), 404);
103 104 105 106
	}
}
else
{
107
	$response = System\Response::prepare($response);
108 109 110 111 112
}

// ----------------------------------------------------------
// Execute the global "after" filter.
// ----------------------------------------------------------
113
System\Route\Filter::call('after', array($response));
114

115 116 117 118 119
// ----------------------------------------------------------
// Stringify the response.
// ----------------------------------------------------------
$response->content = (string) $response->content;

120 121 122 123 124 125 126 127 128 129 130
// --------------------------------------------------------------
// Close the session.
// --------------------------------------------------------------
if (System\Config::get('session.driver') != '')
{
	System\Session::close();
}

// --------------------------------------------------------------
// Send the response to the browser.
// --------------------------------------------------------------
131
$response->send();