-
Notifications
You must be signed in to change notification settings - Fork 297
/
index.php
226 lines (189 loc) · 6 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/**
* Fuel is a fast, lightweight, community driven PHP 5.4+ framework.
*
* @package Fuel
* @version 1.9-dev
* @author Fuel Development Team
* @license MIT License
* @copyright 2010 - 2019 Fuel Development Team
* @link https://fuelphp.com
*/
/**
* -----------------------------------------------------------------------------
* Configure PHP Settings
* -----------------------------------------------------------------------------
*/
/**
* -----------------------------------------------------------------------------
* Show error reporting
* -----------------------------------------------------------------------------
*
* Set error reporting and display errors settings.
* You will want to change these when in production.
*
*/
error_reporting(-1);
ini_set('display_errors', 1);
/**
* -----------------------------------------------------------------------------
* Define constants
* -----------------------------------------------------------------------------
*/
/**
* -----------------------------------------------------------------------------
* Website document root
* -----------------------------------------------------------------------------
*/
define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR);
/**
* -----------------------------------------------------------------------------
* Path to the application directory
* -----------------------------------------------------------------------------
*/
define('APPPATH', realpath(__DIR__.'/../fuel/app/').DIRECTORY_SEPARATOR);
/**
* -----------------------------------------------------------------------------
* Path to the default packages directory
* -----------------------------------------------------------------------------
*/
define('PKGPATH', realpath(__DIR__.'/../fuel/packages/').DIRECTORY_SEPARATOR);
/**
* -----------------------------------------------------------------------------
* The path to the framework core
* -----------------------------------------------------------------------------
*/
define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);
/**
* -----------------------------------------------------------------------------
* Profiling
* -----------------------------------------------------------------------------
*/
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());
/**
* -----------------------------------------------------------------------------
* Preparing the Application
* -----------------------------------------------------------------------------
*/
/**
* -----------------------------------------------------------------------------
* Check for dependencies
* -----------------------------------------------------------------------------
*/
if ( ! file_exists(COREPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php'))
{
die('No composer autoloader found. Please run composer to install the FuelPHP framework dependencies first!');
}
/**
* -----------------------------------------------------------------------------
* Activate autoloader class
* -----------------------------------------------------------------------------
*/
require COREPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php';
class_alias('Fuel\\Core\\Autoloader', 'Autoloader');
/**
* -----------------------------------------------------------------------------
* Route processing
* -----------------------------------------------------------------------------
*
* Exception route processing closure
*
*/
$routerequest = function($request = null, $e = false)
{
Request::reset_request(true);
$route = array_key_exists($request, Router::$routes) ? Router::$routes[$request]->translation : Config::get('routes.'.$request);
if ($route instanceof Closure)
{
$response = $route();
if( ! $response instanceof Response)
{
$response = Response::forge($response);
}
}
elseif ($e === false)
{
$response = Request::forge()->execute()->response();
}
elseif ($route)
{
$response = Request::forge($route, false)->execute(array($e))->response();
}
elseif ($request)
{
$response = Request::forge($request)->execute(array($e))->response();
}
else
{
throw $e;
}
return $response;
};
/**
* -----------------------------------------------------------------------------
* Starting the Application
* -----------------------------------------------------------------------------
*/
/**
* -----------------------------------------------------------------------------
* Start the engine
* -----------------------------------------------------------------------------
*
* Generate the request, execute it and send the output
*
*/
try
{
// Boot the app...
require APPPATH.'bootstrap.php';
// ... and execute the main request
$response = $routerequest();
}
catch (HttpBadRequestException $e)
{
$response = $routerequest('_400_', $e);
}
catch (HttpNoAccessException $e)
{
$response = $routerequest('_403_', $e);
}
catch (HttpNotFoundException $e)
{
$response = $routerequest('_404_', $e);
}
catch (HttpServerErrorException $e)
{
$response = $routerequest('_500_', $e);
}
$response->body((string) $response);
/**
* -----------------------------------------------------------------------------
* Start profiling
* -----------------------------------------------------------------------------
*
* This will add the execution time and memory usage to the output.
*
* Comment these out if you don't use it.
*
*/
if (strpos($response->body(), '{exec_time}') !== false or strpos($response->body(), '{mem_usage}') !== false)
{
$bm = Profiler::app_total();
$response->body(
str_replace(
array('{exec_time}', '{mem_usage}'),
array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
$response->body()
)
);
}
/**
* -----------------------------------------------------------------------------
* Show the web page
* -----------------------------------------------------------------------------
*
* Send the output to the client
*
*/
$response->send(true);