laravel.php 3.19 KB
Newer Older
Taylor Otwell committed
1 2
<?php namespace Laravel;

3
/**
4 5 6
 * Bootstrap the core framework components like the IoC container,
 * configuration class, and the class auto-loader. Once this file
 * has run, the framework is essentially ready for use.
7
 */
Taylor Otwell committed
8
require 'bootstrap/core.php';
9

10
/**
11 12 13
 * Register the framework error handling methods and set the
 * error_reporting levels. This file will register handlers
 * for exceptions, errors, and shutdown.
14
 */
Taylor Otwell committed
15
require SYS_PATH.'bootstrap/errors'.EXT;
16

17 18 19
/**
 * Set the application's default timezone.
 */
Taylor Otwell committed
20
date_default_timezone_set(Config::$items['application']['timezone']);
21

22
/**
23 24 25
 * 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.
26
 */
Taylor Otwell committed
27
if (Config::$items['session']['driver'] !== '')
28
{
29
	$driver = IoC::container()->core('session.'.Config::$items['session']['driver']);
30

31 32 33
	$transporter = IoC::container()->core('session.transporter');

	Session\Manager::start($driver, $transporter);
34
}
35

36
/**
37 38
 * Manually load some core classes that are used on every request
 * This allows to avoid using the loader for these classes.
39
 */
40
require SYS_PATH.'request'.EXT;
41
require SYS_PATH.'routing/route'.EXT;
42
require SYS_PATH.'routing/router'.EXT;
43
require SYS_PATH.'routing/loader'.EXT;
44
require SYS_PATH.'routing/filter'.EXT;
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
/**
 * Gather the input to the application for the current request.
 * The input will be gathered based on the current request method
 * and will be set on the Input manager.
 */
$input = array();

switch (Request::method())
{
	case 'GET':
		$input = $_GET;
		break;

	case 'POST':
		$input = $_POST;
		break;
Taylor Otwell committed
62

63 64 65 66 67 68 69 70 71 72 73 74
	case 'PUT':
	case 'DELETE':
		if (Request::spoofed())
		{
			$input = $_POST;
		}
		else
		{
			parse_str(file_get_contents('php://input'), $input);
		}
}

75 76 77 78
/**
 * The spoofed request method is removed from the input so it is
 * not unexpectedly included in Input::all() or Input::get().s
 */
79 80
unset($input[Request::spoofer]);

81
Input::$input = $input;
82 83 84 85 86 87 88

/**
 * 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.
 */
89 90
Routing\Filter::register(require APP_PATH.'filters'.EXT);

91
list($uri, $method) = array(Request::uri(), Request::method());
Taylor Otwell committed
92

93
$route = IoC::container()->core('routing.router')->route($method, $uri);
94 95 96

if ( ! is_null($route))
{
97
	$response = $route->call();
98 99 100
}
else
{
101
	$response = Response::error('404');
102
}
103

104
/**
105 106 107 108
 * Stringify the response. We need to force the response to be
 * stringed before closing the session, since the developer may
 * be using the session within their views, so we cannot age
 * the session data until the view is rendered.
109
 */
110
$response->content = $response->render();
111

112
/**
113 114 115 116
 * Close the session and write the active payload to persistent
 * storage. The input for the current request is also flashed
 * to the session so it will be available for the next request
 * via the Input::old method.
117
 */
118
if (Config::$items['session']['driver'] !== '')
Taylor Otwell committed
119
{
120
	Session\Manager::close(array(Input::old_input => Input::get()));
Taylor Otwell committed
121
}
122

123 124 125
/**
 * Finally, we can send the response to the browser.
 */
126
$response->send();