This repository was archived by the owner on Aug 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootstrap.php
More file actions
256 lines (226 loc) · 6.83 KB
/
Bootstrap.php
File metadata and controls
256 lines (226 loc) · 6.83 KB
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
<?php
/**
* GSC Tesseract
* php version 8.2
*
* @category CMS
* @package Framework
* @author Fred Brooker <git@gscloud.cz>
* @license MIT https://gscloud.cz/LICENSE.txt
* @link https://mini.gscloud.cz
*/
declare (strict_types = 1);
use Nette\Neon\Neon;
use Tracy\Debugger;
define('TESSERACT_START', microtime(true));
// CLI SAPI external include
if (PHP_SAPI === 'cli') {
$req = getenv('CLI_REQ');
if ($req && file_exists($req) && is_readable($req)) {
include_once $req;
}
}
// PHP INI
ini_set(
'auto_detect_line_endings',
defined('AUTO_DETECT_LINE_ENDINGS') ? AUTO_DETECT_LINE_ENDINGS : 'true'
);
ini_set(
'default_socket_timeout',
defined('DEFAULT_SOCKET_TIMEOUT') ? DEFAULT_SOCKET_TIMEOUT : '15'
);
ini_set(
'display_errors',
defined('DISPLAY_ERRORS') ? DISPLAY_ERRORS : 'true'
);
ob_start();
error_reporting(E_ALL);
// directory separator
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
// app root
defined('ROOT') || define('ROOT', __DIR__);
// Apache root, not mandatory for the main code
defined('WWW') || define('WWW', ROOT . DS . 'www');
// APP directory, mandatory for the main code (App.php etc. loaded from here)
$d = 'APP';
$x = ROOT . DS . 'app';
if (defined($d) && is_dir($x) && is_readable($x)) {
} else {
if (is_dir($x) && is_readable($x)) {
define($d, $x);
} else {
die('Could not read the APP directory: ' . $x);
}
}
// CACHE directory, can use system temp
$d = 'CACHE';
$x = ROOT . DS . 'temp';
if (defined($d) && is_dir($x) && is_readable($x)) {
} else {
if (is_dir($x) && is_writable($x)) {
define($d, $x);
} else {
define($d, '/tmp');
}
}
// DATA directory, can use system temp
$d = 'DATA';
$x = ROOT . DS . 'data';
if (defined($d) && is_dir($x) && is_writable($x)) {
} else {
if (is_dir($x) && is_writable($x)) {
define($d, $x);
} else {
define($d, '/tmp');
}
}
// configuration file, test later
defined('CONFIG') || define('CONFIG', APP . DS . 'config.neon');
// private configuration file, not mandatory, test later
defined('CONFIG_PRIVATE') || define(
'CONFIG_PRIVATE', APP . DS . 'config_private.neon'
);
// CSP definition file, used in App.php, not mandatory - can use system temp
$d = 'CSP';
$x = APP . DS . 'csp.neon';
if (file_exists($x) && is_readable($x)) {
defined($d) || define($d, $x);
} else {
defined($d) || define($d, null);
}
// Mustache templates, not mandatory - can use system temp
$d = 'TEMPLATES';
$x = APP . DS . 'templates';
if (is_dir($x) && is_readable($x)) {
defined($d) || define($d, $x);
} else {
defined($d) || define($d, '/tmp');
}
// Mustache partials, not mandatory - can use system temp
$d = 'PARTIALS';
$x = APP . DS . 'partials';
if (is_dir($x) && is_readable($x)) {
defined($d) || define($d, $x);
} else {
defined($d) || define($d, '/tmp');
}
// DOWNLOAD storage = files generated by Tesseract, not mandatory
$d = 'DOWNLOAD';
$x = WWW . DS . 'download';
if (is_dir($x) && is_readable($x)) {
defined($d) || define($d, $x);
} else {
defined($d) || define($d, null);
}
// UPLOAD storage = files uploaded by users, not mandatory
$d = 'UPLOAD';
$x = WWW . DS . 'upload';
if (is_dir($x) && is_readable($x)) {
defined($d) || define($d, $x);
} else {
defined($d) || define($d, null);
}
// LOGS storage for Tracy, not mandatory
$d = 'LOGS';
$x = ROOT . DS . 'logs';
if (is_dir($x) && is_writable($x)) {
defined($d) || define($d, $x);
} else {
defined($d) || define($d, null);
}
// TEMP files storage, not mandatory - can use system temp
$d = 'TEMP';
$x = ROOT . DS . 'temp';
if (is_dir($x) && is_writable($x)) {
defined($d) || define('TEMP', $x);
} else {
defined($d) || define($d, '/tmp');
}
// running from CLI?
defined('CLI') || define('CLI', (bool) (PHP_SAPI == 'cli'));
// running from localhost?
defined('LOCALHOST') || define(
'LOCALHOST', (bool) (($_SERVER['SERVER_NAME'] ?? '') == 'localhost') || CLI
);
// Composer autoloader
require_once ROOT . DS . 'vendor' . DS . 'autoload.php';
// load CONFIGURATION
$cfg = null;
if (file_exists(CONFIG) && is_readable(CONFIG)) {
$cfg_content = file_get_contents(CONFIG);
if ($cfg_content) {
$cfg = Neon::decode($cfg_content);
} else {
$cfg = null;
}
if (!is_array($cfg)) {
die('FATAL ERROR: INVALID MAIN CONFIG!');
}
try {
if (file_exists(CONFIG_PRIVATE) && is_readable(CONFIG_PRIVATE)) {
$priv_content = file_get_contents(CONFIG_PRIVATE);
if ($priv_content) {
$priv = Neon::decode($priv_content);
} else {
$priv = null;
}
if (!is_array($priv)) {
throw new Exception('FATAL ERROR: PRIVATE CONFIG IS NOT AN ARRAY!');
}
$cfg = array_replace_recursive($cfg, $priv);
}
} catch (Exception $e) {
die('FATAL ERROR: INVALID PRIVATE CONFIG!');
}
}
if (!is_array($cfg)) {
die('FATAL ERROR: INVALID MAIN CONFIG!');
}
// DEFAULT TIME ZONE
date_default_timezone_set(
(string) ($cfg['date_default_timezone'] ?? 'Europe/Prague')
);
// DEBUGGER
if (CLI === true) {
defined('DEBUG') || define('DEBUG', false);
}
if (($_SERVER['SERVER_NAME'] ?? '') === 'localhost') {
if (($cfg['dbg'] ?? null) === false) {
defined('DEBUG') || define('DEBUG', false); // DISABLED - configuration
}
defined('DEBUG') || define('DEBUG', true); // ENABLED - localhost
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'curl') !== false) {
defined('DEBUG') || define('DEBUG', false); // DISABLED - curl
}
}
defined('DEBUG') || define('DEBUG', (bool) ($cfg['dbg'] ?? false));
if (DEBUG === true) {
// https://api.nette.org/tracy/master/Tracy.html
// https://www.php.net/manual/en/errorfunc.constants.php
Debugger::$logDirectory = LOGS;
Debugger::$logSeverity = 15;
Debugger::$maxDepth = (int) ($cfg['DEBUG_MAX_DEPTH'] ?? 10);
Debugger::$maxLength = (int) ($cfg['DEBUG_MAX_LENGTH'] ?? 5000);
Debugger::$scream = (bool) ($cfg['DEBUG_SCREAM'] ?? true);
Debugger::$showBar = (bool) ($cfg['DEBUG_SHOW_BAR'] ?? true);
Debugger::$showFireLogger = (bool) ($cfg['DEBUG_SHOW_FIRELOGGER'] ?? false);
Debugger::$showLocation = (bool) ($cfg['DEBUG_SHOW_LOCATION'] ?? false);
Debugger::$strictMode = (bool) ($cfg['DEBUG_STRICT_MODE'] ?? true);
// debug cookie name: tracy-debug
if ($cfg['DEBUG_COOKIE'] ?? null) {
if (($_COOKIE['tracy-debug'] ?? null) === $cfg['DEBUG_COOKIE']) {
Debugger::enable(Debugger::Development);
} else {
Debugger::enable(Debugger::Production);
}
} else {
Debugger::enable(
(bool) ($cfg['DEBUG_DEVELOPMENT_MODE'] ?? true)
? Debugger::DEVELOPMENT : Debugger::DETECT, LOGS
);
}
}
Debugger::timer('RUN');
require_once APP . DS . 'App.php';