-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.inc.php
73 lines (66 loc) · 2.71 KB
/
bootstrap.inc.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
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
function autoloader($class) {
$c = strtolower($class);
if (isset($GLOBALS['AUTOLOAD'][$c])) {
require_once($GLOBALS['AUTOLOAD'][$c]);
return true;
}
return spl_autoload(str_replace('_', '/', $class));
}
error_reporting(E_ALL);
set_error_handler('exception_error_handler');
spl_autoload_register('autoloader');
$GLOBALS['AUTOLOAD'] = array();
$GLOBALS['ENVIRONMENT'] = isset($_SERVER['ENVIRONMENT']) ? strtolower($_SERVER['ENVIRONMENT']) : 'development';
$GLOBALS['APPLICATION_ROOT'] = dirname(__FILE__);
$GLOBALS['HTTP_ROOT'] = 'http://localhost/';
set_include_path(get_include_path() . PATH_SEPARATOR . $GLOBALS['APPLICATION_ROOT'].'/lib/');
// Manually specified plugins. Useful for controlling load-order
$GLOBALS['PLUGINS'] = array();
if (is_file($GLOBALS['APPLICATION_ROOT'].'/config/plugins.inc.php')) {
require_once($GLOBALS['APPLICATION_ROOT'].'/config/plugins.inc.php');
}
// Discover thirdparty plugins
foreach (scandir($GLOBALS['APPLICATION_ROOT'].'/vendor') as $plugin) {
if (!array_key_exists($plugin, $GLOBALS['PLUGINS'])) {
if (substr($plugin, 0, 1) !== '.') {
$GLOBALS['PLUGINS'][$plugin] = $GLOBALS['APPLICATION_ROOT'].'/vendor/'.$plugin;
}
}
}
// Register plugins
foreach ($GLOBALS['PLUGINS'] as $plugin => $path) {
set_include_path(get_include_path() . PATH_SEPARATOR . $path.'/lib');
}
// Load various global functions/bindings used throughout the application
require_once 'common_globals.inc.php';
// Load environment
// Include default config
include($GLOBALS['APPLICATION_ROOT'].'/config/environment.inc.php');
// Include local config
if (is_file($GLOBALS['APPLICATION_ROOT'].'/config/environment.local.inc.php')) {
include($GLOBALS['APPLICATION_ROOT'].'/config/environment.local.inc.php');
}
// Include env config
if (is_file($GLOBALS['APPLICATION_ROOT'].'/config/environments/'.$GLOBALS['ENVIRONMENT'].'.php')) {
include($GLOBALS['APPLICATION_ROOT'].'/config/environments/'.$GLOBALS['ENVIRONMENT'].'.php');
}
// Include local env config
if (is_file($GLOBALS['APPLICATION_ROOT'].'/config/environments/'.$GLOBALS['ENVIRONMENT'].'.local.php')) {
include($GLOBALS['APPLICATION_ROOT'].'/config/environments/'.$GLOBALS['ENVIRONMENT'].'.local.php');
}
// Load routes
include($GLOBALS['APPLICATION_ROOT'].'/config/routes.inc.php');
// Include autoload mapping
if (is_file($GLOBALS['APPLICATION_ROOT'].'/config/autoload.inc.php')) {
include($GLOBALS['APPLICATION_ROOT'].'/config/autoload.inc.php');
}
// Init plugins
foreach ($GLOBALS['PLUGINS'] as $plugin => $path) {
if (is_file($path.'/bootstrap.inc.php')) {
include($path.'/bootstrap.inc.php');
}
}