This repository has been archived by the owner on Oct 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
bootstrap.php
executable file
·170 lines (143 loc) · 4.06 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
<?php
declare(strict_types=1);
use \Airship\Engine\State;
if (!\defined('ROOT')) {
require_once __DIR__.'/preload.php';
}
/**
* @global State $state
*/
/**
* 1. Load all of the gears.
*/
$gears = \Airship\loadJSON(ROOT.'/config/gears.json');
foreach ($gears as $gear) {
$ns = isset($gear['supplier'])
? $gear['supplier'].'\\'.$gear['name']
: $gear['name'];
// Load the gears first:
\Airship\autoload(
'\\Airship\\Gears\\'.$ns,
'~/Gears/'.\str_replace('\\', '/', $ns)
);
}
/**
* 2. After loading the gears, we set up the cabins
*/
require_once ROOT . '/cabins.php';
\Airship\autoload('\\Airship\\Cabin', '~/Cabin');
/**
* 3. Let's bootstrap the routes and other configuration
* for the current cabin (set in cabins.php)
*/
$active = $state->cabins[$state->active_cabin];
$state->lang = isset($active['lang'])
? $active['lang']
: 'en-us'; // default
if (!\ISCLI) {
$cabinFile = \implode(DIRECTORY_SEPARATOR, [
ROOT,
'tmp',
'cabin.' . $active['name'] . '.offline.txt'
]);
if (\file_exists($cabinFile)) {
// There might be an automatic update in progress!
// Let's give it up to 15 seconds, but only as much time as is needed.
$iter = 0;
do {
if (!\file_exists($cabinFile)) {
break;
}
\usleep(100);
++$iter;
} while($iter < 15000);
\clearstatcache();
// If we're still in the middle of that process, let's not load anything else:
if (\file_exists($cabinFile)) {
echo \__('This Airship is currently docked for routine maintenance. Please try again later.'), "\n";
exit(255);
}
}
}
// Let's set the current language:
$lang = \preg_replace_callback(
'#([A-Za-z]+)\-([a-zA-Z]+)#',
function($matches) {
return \strtolower($matches[1]).'_'.\strtoupper($matches[2]);
},
$state->lang
).
'.UTF-8';
\putenv('LANG='.$lang);
// Overload the active template
if (isset($active['data']['base_template'])) {
$state->base_template = $active['data']['base_template'];
} else {
$state->base_template = 'base.twig';
}
$twigLoader = new \Twig_Loader_Filesystem(
ROOT.'/Cabin/'.$active['name'].'/Lens'
);
$lensLoad = [];
// Load all the gadgets, which can act on $twigLoader
include ROOT.'/config/gadgets.php';
$twigOpts = [
'debug' => $state->universal['debug']
];
if (!empty($state->universal['twig-cache'])) {
$twigOpts['cache'] = ROOT . '/tmp/cache/twig';
}
$twigEnv = new \Twig_Environment($twigLoader, $twigOpts);
$twigEnv->addExtension(new \Twig_Extension_Debug());
$lens = \Airship\Engine\Gears::get('Lens', $twigEnv);
// Load the Lens configuration
include ROOT.'/config/lens.php';
// Load the Cabin-specific filters etc, if applicable:
if (\file_exists(ROOT.'/Cabin/'.$active['name'].'/lens.php')) {
include ROOT.'/Cabin/'.$active['name'].'/lens.php';
}
// Load the template variables for this Cabin:
if (\file_exists(ROOT.'/config/Cabin/'.$active['name'].'/twig_vars.json')) {
$_settings = \Airship\loadJSON(
ROOT.'/config/Cabin/'.$active['name'].'/twig_vars.json'
);
$lens->addGlobal(
'SETTINGS',
$_settings
);
}
// Now let's load all the lens.php files
foreach ($lensLoad as $incl) {
include $incl;
}
/**
* Let's load up the databases
*/
$dbPool = [];
require ROOT.'/database.php';
$universal = \Airship\loadJSON(ROOT.'/config/universal.json');
$state->universal = $universal;
$manifest = \Airship\loadJSON(ROOT.'/config/manifest.json');
$state->manifest = $manifest;
$htmlpurifier = new \HTMLPurifier(
\HTMLPurifier_Config::createDefault()
);
$state->HTMLPurifier = $htmlpurifier;
/**
* Load up all of the keys used by the application:
*/
require_once ROOT.'/keys.php';
/**
* Set up the logger
*/
require_once ROOT."/config/logger.php";
/**
* Automatic security updates
*/
$hail = \Airship\Engine\Gears::get(
'Hail',
new \GuzzleHttp\Client($state->universal['guzzle'])
);
$state->hail = $hail;
// Let's start our session:
require_once ROOT.'/session.php';