-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
359 lines (284 loc) · 17.4 KB
/
bootstrap.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?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
*/
define('DS', DIRECTORY_SEPARATOR);
define('CRLF', chr(13).chr(10));
/**
* Do we have access to mbstring?
* We need this in order to work with UTF-8 strings
*/
if ( ! defined('MBSTRING'))
{
// we do not support mb function overloading
if (ini_get('mbstring.func_overload'))
{
die('Your PHP installation is configured to overload mbstring functions. This is not supported in FuelPHP!');
}
define('MBSTRING', function_exists('mb_get_info'));
}
// load the base functions
require COREPATH.'base.php';
// define the core classes to the autoloader
setup_autoloader();
// setup the composer autoloader
get_composer();
/**
* Register all the error/shutdown handlers
*/
register_shutdown_function(function ()
{
// reset the autoloader
\Autoloader::_reset();
// if we have sessions loaded, and native session emulation active
if (\Config::get('session.native_emulation', false))
{
// close the name session
session_id() and session_write_close();
}
// make sure we're having an output filter so we can display errors
// occuring before the main config file is loaded
\Config::get('security.output_filter', null) or \Config::set('security.output_filter', 'Security::htmlentities');
try
{
// fire any app shutdown events
\Event::instance()->trigger('shutdown', '', 'none', true);
// fire any framework shutdown events
\Event::instance()->trigger('fuel-shutdown', '', 'none', true);
}
catch (\Exception $e)
{
if (\Fuel::$is_cli)
{
\Cli::error("Error: ".$e->getMessage()." in ".$e->getFile()." on ".$e->getLine());
\Cli::beep();
exit(1);
}
else
{
logger(\Fuel::L_ERROR, 'shutdown - ' . $e->getMessage()." in ".$e->getFile()." on ".$e->getLine());
}
}
return \Errorhandler::shutdown_handler();
});
set_exception_handler(function ($e)
{
// reset the autoloader
\Autoloader::_reset();
// deal with PHP bugs #42098/#54054
if ( ! class_exists('Errorhandler'))
{
include COREPATH.'classes/errorhandler.php';
class_alias('\Fuel\Core\Errorhandler', 'Errorhandler');
class_alias('\Fuel\Core\PhpErrorException', 'PhpErrorException');
}
return \Errorhandler::exception_handler($e);
});
set_error_handler(function ($severity, $message, $filepath, $line)
{
// reset the autoloader
\Autoloader::_reset();
// deal with PHP bugs #42098/#54054
if ( ! class_exists('Errorhandler'))
{
include COREPATH.'classes/errorhandler.php';
class_alias('\Fuel\Core\Errorhandler', 'Errorhandler');
class_alias('\Fuel\Core\PhpErrorException', 'PhpErrorException');
}
return \Errorhandler::error_handler($severity, $message, $filepath, $line);
});
function setup_autoloader()
{
\Autoloader::add_namespace('Fuel\\Core', COREPATH.'classes/');
\Autoloader::add_classes(array(
'Fuel\\Core\\Agent' => COREPATH.'classes/agent.php',
'Fuel\\Core\\Arr' => COREPATH.'classes/arr.php',
'Fuel\\Core\\Asset' => COREPATH.'classes/asset.php',
'Fuel\\Core\\Asset_Instance' => COREPATH.'classes/asset/instance.php',
'Fuel\\Core\\Cache' => COREPATH.'classes/cache.php',
'Fuel\\Core\\CacheNotFoundException' => COREPATH.'classes/cache/notfound.php',
'Fuel\\Core\\CacheExpiredException' => COREPATH.'classes/cache.php',
'Fuel\\Core\\Cache_Handler_Driver' => COREPATH.'classes/cache/handler/driver.php',
'Fuel\\Core\\Cache_Handler_Json' => COREPATH.'classes/cache/handler/json.php',
'Fuel\\Core\\Cache_Handler_Serialized' => COREPATH.'classes/cache/handler/serialized.php',
'Fuel\\Core\\Cache_Handler_String' => COREPATH.'classes/cache/handler/string.php',
'Fuel\\Core\\Cache_Storage_Driver' => COREPATH.'classes/cache/storage/driver.php',
'Fuel\\Core\\Cache_Storage_Apc' => COREPATH.'classes/cache/storage/apc.php',
'Fuel\\Core\\Cache_Storage_File' => COREPATH.'classes/cache/storage/file.php',
'Fuel\\Core\\Cache_Storage_Memcached' => COREPATH.'classes/cache/storage/memcached.php',
'Fuel\\Core\\Cache_Storage_Redis' => COREPATH.'classes/cache/storage/redis.php',
'Fuel\\Core\\Cache_Storage_Xcache' => COREPATH.'classes/cache/storage/xcache.php',
'Fuel\\Core\\Config' => COREPATH.'classes/config.php',
'Fuel\\Core\\ConfigException' => COREPATH.'classes/config.php',
'Fuel\\Core\\Config_Db' => COREPATH.'classes/config/db.php',
'Fuel\\Core\\Config_File' => COREPATH.'classes/config/file.php',
'Fuel\\Core\\Config_Ini' => COREPATH.'classes/config/ini.php',
'Fuel\\Core\\Config_Json' => COREPATH.'classes/config/json.php',
'Fuel\\Core\\Config_Interface' => COREPATH.'classes/config/interface.php',
'Fuel\\Core\\Config_Php' => COREPATH.'classes/config/php.php',
'Fuel\\Core\\Config_Yml' => COREPATH.'classes/config/yml.php',
'Fuel\\Core\\Config_Memcached' => COREPATH.'classes/config/memcached.php',
'Fuel\\Core\\Controller' => COREPATH.'classes/controller.php',
'Fuel\\Core\\Controller_Rest' => COREPATH.'classes/controller/rest.php',
'Fuel\\Core\\Controller_Template' => COREPATH.'classes/controller/template.php',
'Fuel\\Core\\Controller_Hybrid' => COREPATH.'classes/controller/hybrid.php',
'Fuel\\Core\\Cookie' => COREPATH.'classes/cookie.php',
'Fuel\\Core\\DB' => COREPATH.'classes/db.php',
'Fuel\\Core\\DBUtil' => COREPATH.'classes/dbutil.php',
'Fuel\\Core\\Database_Connection' => COREPATH.'classes/database/connection.php',
'Fuel\\Core\\Database_Result' => COREPATH.'classes/database/result.php',
'Fuel\\Core\\Database_Exception' => COREPATH.'classes/database/exception.php',
'Fuel\\Core\\Database_Expression' => COREPATH.'classes/database/expression.php',
// Generic Schema builder
'Fuel\\Core\\Database_Schema' => COREPATH.'classes/database/schema.php',
// Specific Schema builders
// Generic Query builder
'Fuel\\Core\\Database_Query' => COREPATH.'classes/database/query.php',
'Fuel\\Core\\Database_Query_Builder' => COREPATH.'classes/database/query/builder.php',
'Fuel\\Core\\Database_Query_Builder_Insert' => COREPATH.'classes/database/query/builder/insert.php',
'Fuel\\Core\\Database_Query_Builder_Delete' => COREPATH.'classes/database/query/builder/delete.php',
'Fuel\\Core\\Database_Query_Builder_Update' => COREPATH.'classes/database/query/builder/update.php',
'Fuel\\Core\\Database_Query_Builder_Select' => COREPATH.'classes/database/query/builder/select.php',
'Fuel\\Core\\Database_Query_Builder_Where' => COREPATH.'classes/database/query/builder/where.php',
'Fuel\\Core\\Database_Query_Builder_Join' => COREPATH.'classes/database/query/builder/join.php',
// Specific Query builders
'Fuel\\Core\\Database_SQLite_Builder_Delete' => COREPATH.'classes/database/sqlite/builder/delete.php',
'Fuel\\Core\\Database_SQLite_Builder_Update' => COREPATH.'classes/database/sqlite/builder/update.php',
'Fuel\\Core\\Database_Sqlsrv_Builder_Delete' => COREPATH.'classes/database/sqlsrv/builder/delete.php',
'Fuel\\Core\\Database_Sqlsrv_Builder_Select' => COREPATH.'classes/database/sqlsrv/builder/select.php',
// Generic PDO driver
'Fuel\\Core\\Database_Pdo_Connection' => COREPATH.'classes/database/pdo/connection.php',
'Fuel\\Core\\Database_Pdo_Result' => COREPATH.'classes/database/pdo/result.php',
'Fuel\\Core\\Database_Pdo_Cached' => COREPATH.'classes/database/pdo/cached.php',
// Platform specific PDO drivers
'Fuel\\Core\\Database_MySQL_Connection' => COREPATH.'classes/database/mysql/connection.php',
'Fuel\\Core\\Database_SQLite_Connection' => COREPATH.'classes/database/sqlite/connection.php',
'Fuel\\Core\\Database_Sqlsrv_Connection' => COREPATH.'classes/database/sqlsrv/connection.php',
'Fuel\\Core\\Database_Dblib_Connection' => COREPATH.'classes/database/dblib/connection.php',
// Legacy MySQL driver
'Fuel\\Core\\Database_MySQLi_Connection' => COREPATH.'classes/database/mysqli/connection.php',
'Fuel\\Core\\Database_MySQLi_Result' => COREPATH.'classes/database/mysqli/result.php',
'Fuel\\Core\\Database_MySQLi_Cached' => COREPATH.'classes/database/mysqli/cached.php',
'Fuel\\Core\\Fuel' => COREPATH.'classes/fuel.php',
'Fuel\\Core\\FuelException' => COREPATH.'classes/fuel.php',
'Fuel\\Core\\Finder' => COREPATH.'classes/finder.php',
'Fuel\\Core\\Date' => COREPATH.'classes/date.php',
'Fuel\\Core\\Debug' => COREPATH.'classes/debug.php',
'Fuel\\Core\\Cli' => COREPATH.'classes/cli.php',
'Fuel\\Core\\Crypt' => COREPATH.'classes/crypt.php',
'Fuel\\Core\\Event' => COREPATH.'classes/event.php',
'Fuel\\Core\\Event_Instance' => COREPATH.'classes/event/instance.php',
'Fuel\\Core\\Errorhandler' => COREPATH.'classes/errorhandler.php',
'Fuel\\Core\\PhpErrorException' => COREPATH.'classes/errorhandler.php',
'Fuel\\Core\\Format' => COREPATH.'classes/format.php',
'Fuel\\Core\\Fieldset' => COREPATH.'classes/fieldset.php',
'Fuel\\Core\\Fieldset_Field' => COREPATH.'classes/fieldset/field.php',
'Fuel\\Core\\File' => COREPATH.'classes/file.php',
'Fuel\\Core\\FileAccessException' => COREPATH.'classes/file.php',
'Fuel\\Core\\OutsideAreaException' => COREPATH.'classes/file.php',
'Fuel\\Core\\InvalidPathException' => COREPATH.'classes/file.php',
'Fuel\\Core\\File_Area' => COREPATH.'classes/file/area.php',
'Fuel\\Core\\File_Handler_File' => COREPATH.'classes/file/handler/file.php',
'Fuel\\Core\\File_Handler_Directory' => COREPATH.'classes/file/handler/directory.php',
'Fuel\\Core\\Form' => COREPATH.'classes/form.php',
'Fuel\\Core\\Form_Instance' => COREPATH.'classes/form/instance.php',
'Fuel\\Core\\Ftp' => COREPATH.'classes/ftp.php',
'Fuel\\Core\\FtpConnectionException' => COREPATH.'classes/ftp.php',
'Fuel\\Core\\FtpFileAccessException' => COREPATH.'classes/ftp.php',
'Fuel\\Core\\HttpException' => COREPATH.'classes/httpexception.php',
'Fuel\\Core\\HttpBadRequestException' => COREPATH.'classes/httpexceptions.php',
'Fuel\\Core\\HttpNoAccessException' => COREPATH.'classes/httpexceptions.php',
'Fuel\\Core\\HttpNotFoundException' => COREPATH.'classes/httpexceptions.php',
'Fuel\\Core\\HttpServerErrorException' => COREPATH.'classes/httpexceptions.php',
'Fuel\\Core\\Html' => COREPATH.'classes/html.php',
'Fuel\\Core\\Image' => COREPATH.'classes/image.php',
'Fuel\\Core\\Image_Driver' => COREPATH.'classes/image/driver.php',
'Fuel\\Core\\Image_Gd' => COREPATH.'classes/image/gd.php',
'Fuel\\Core\\Image_Imagemagick' => COREPATH.'classes/image/imagemagick.php',
'Fuel\\Core\\Image_Imagick' => COREPATH.'classes/image/imagick.php',
'Fuel\\Core\\Inflector' => COREPATH.'classes/inflector.php',
'Fuel\\Core\\Input' => COREPATH.'classes/input.php',
'Fuel\\Core\\Input_Instance' => COREPATH.'classes/input/instance.php',
'Fuel\\Core\\Lang' => COREPATH.'classes/lang.php',
'Fuel\\Core\\LangException' => COREPATH.'classes/lang.php',
'Fuel\\Core\\Lang_Db' => COREPATH.'classes/lang/db.php',
'Fuel\\Core\\Lang_File' => COREPATH.'classes/lang/file.php',
'Fuel\\Core\\Lang_Ini' => COREPATH.'classes/lang/ini.php',
'Fuel\\Core\\Lang_Json' => COREPATH.'classes/lang/json.php',
'Fuel\\Core\\Lang_Interface' => COREPATH.'classes/lang/interface.php',
'Fuel\\Core\\Lang_Php' => COREPATH.'classes/lang/php.php',
'Fuel\\Core\\Lang_Yml' => COREPATH.'classes/lang/yml.php',
'Fuel\\Core\\Log' => COREPATH.'classes/log.php',
'Fuel\\Core\\Markdown' => COREPATH.'classes/markdown.php',
'Fuel\\Core\\Migrate' => COREPATH.'classes/migrate.php',
'Fuel\\Core\\Model' => COREPATH.'classes/model.php',
'Fuel\\Core\\Model_Crud' => COREPATH.'classes/model/crud.php',
'Fuel\\Core\\Module' => COREPATH.'classes/module.php',
'Fuel\\Core\\ModuleNotFoundException' => COREPATH.'classes/module.php',
'Fuel\\Core\\Mongo_Db' => COREPATH.'classes/mongo/db.php',
'Fuel\\Core\\Mongo_DbException' => COREPATH.'classes/mongo/db.php',
'Fuel\\Core\\Package' => COREPATH.'classes/package.php',
'Fuel\\Core\\PackageNotFoundException' => COREPATH.'classes/package.php',
'Fuel\\Core\\Pagination' => COREPATH.'classes/pagination.php',
'Fuel\\Core\\Presenter' => COREPATH.'classes/presenter.php',
'Fuel\\Core\\Profiler' => COREPATH.'classes/profiler.php',
'Fuel\\Core\\Request' => COREPATH.'classes/request.php',
'Fuel\\Core\\Request_Driver' => COREPATH.'classes/request/driver.php',
'Fuel\\Core\\RequestException' => COREPATH.'classes/request/driver.php',
'Fuel\\Core\\RequestStatusException' => COREPATH.'classes/request/driver.php',
'Fuel\\Core\\Request_Curl' => COREPATH.'classes/request/curl.php',
'Fuel\\Core\\Request_Soap' => COREPATH.'classes/request/soap.php',
'Fuel\\Core\\Redis_Db' => COREPATH.'classes/redis/db.php',
'Fuel\\Core\\RedisException' => COREPATH.'classes/redis/db.php',
'Fuel\\Core\\Response' => COREPATH.'classes/response.php',
'Fuel\\Core\\Route' => COREPATH.'classes/route.php',
'Fuel\\Core\\Router' => COREPATH.'classes/router.php',
'Fuel\\Core\\Sanitization' => COREPATH.'classes/sanitization.php',
'Fuel\\Core\\Security' => COREPATH.'classes/security.php',
'Fuel\\Core\\SecurityException' => COREPATH.'classes/security.php',
'Fuel\\Core\\Session' => COREPATH.'classes/session.php',
'Fuel\\Core\\Session_Driver' => COREPATH.'classes/session/driver.php',
'Fuel\\Core\\Session_Db' => COREPATH.'classes/session/db.php',
'Fuel\\Core\\Session_Cookie' => COREPATH.'classes/session/cookie.php',
'Fuel\\Core\\Session_File' => COREPATH.'classes/session/file.php',
'Fuel\\Core\\Session_Memcached' => COREPATH.'classes/session/memcached.php',
'Fuel\\Core\\Session_Redis' => COREPATH.'classes/session/redis.php',
'Fuel\\Core\\Session_Exception' => COREPATH.'classes/session/exception.php',
'Fuel\\Core\\Num' => COREPATH.'classes/num.php',
'Fuel\\Core\\Str' => COREPATH.'classes/str.php',
'Fuel\\Core\\TestCase' => COREPATH.'classes/testcase.php',
'Fuel\\Core\\Theme' => COREPATH.'classes/theme.php',
'Fuel\\Core\\ThemeException' => COREPATH.'classes/theme.php',
'Fuel\\Core\\Uri' => COREPATH.'classes/uri.php',
'Fuel\\Core\\Unzip' => COREPATH.'classes/unzip.php',
'Fuel\\Core\\Upload' => COREPATH.'classes/upload.php',
'Fuel\\Core\\Validation' => COREPATH.'classes/validation.php',
'Fuel\\Core\\Validation_Error' => COREPATH.'classes/validation/error.php',
'Fuel\\Core\\View' => COREPATH.'classes/view.php',
'Fuel\\Core\\Viewmodel' => COREPATH.'classes/viewmodel.php',
));
};
function get_composer()
{
// storage for the composer autoloader
static $composer;
// load composer
if ( ! $composer)
{
// load the Composer autoloader if present
defined('VENDORPATH') or define('VENDORPATH', realpath(COREPATH.'..'.DS.'vendor').DS);
if ( ! is_file(VENDORPATH.'autoload.php'))
{
die('Composer is not installed. Please run "php composer.phar update" in the root to install Composer');
}
$composer = require(VENDORPATH.'autoload.php');
}
return $composer;
}