-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootstrap.php
164 lines (141 loc) · 5.04 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
<?php
/**
* GSC Tesseract
* php version 8.2
*
* @category CMS
* @package Framework
* @author Fred Brooker <git@gscloud.cz>
* @license MIT https://gscloud.cz/LICENSE
* @link https://mini.gscloud.cz
*/
declare (strict_types = 1);
use Nette\Neon\Neon;
use Tracy\Debugger;
define('TESSERACT_START', microtime(true));
// external include for cli SAPI
if (PHP_SAPI == 'cli') {
$req = getenv('CLI_REQ');
if ($req && file_exists($req) && is_readable($req)) {
include_once $req;
}
}
// PHP INI - modify default configuration
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 : '30'
);
ini_set(
'display_errors',
defined('DISPLAY_ERRORS') ? DISPLAY_ERRORS : 'true'
);
ob_start();
error_reporting(E_ALL);
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
defined('ROOT') || define('ROOT', __DIR__);
defined('APP') || define('APP', ROOT . DS . 'app');
defined('CACHE') || define('CACHE', ROOT . DS . 'temp');
defined('DATA') || define('DATA', ROOT . DS . 'data');
defined('WWW') || define('WWW', ROOT . DS . 'www');
defined('CONFIG') || define('CONFIG', APP . DS . 'config.neon');
defined('CONFIG_PRIVATE') || define(
'CONFIG_PRIVATE', APP . DS . 'config_private.neon'
);
defined('CSP') || define('CSP', APP . DS . 'csp.neon');
defined('TEMPLATES') || define('TEMPLATES', APP . DS . 'templates');
defined('PARTIALS') || define('PARTIALS', APP . DS . 'partials');
defined('DOWNLOAD') || define('DOWNLOAD', WWW . DS . 'download');
defined('UPLOAD') || define('UPLOAD', WWW . DS . 'upload');
defined('LOGS') || define('LOGS', ROOT . DS . 'logs');
defined('TEMP') || define('TEMP', ROOT . DS . 'temp');
defined('CLI') || define('CLI', (bool) (PHP_SAPI == 'cli'));
defined('LOCALHOST') || define(
'LOCALHOST', (bool) (($_SERVER['SERVER_NAME'] ?? '') == 'localhost') || CLI
);
require_once ROOT . DS . 'vendor' . DS . 'autoload.php';
// read 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 CONFIGURATION!\n");
}
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 NOT AN ARRAY');
}
$cfg = array_replace_recursive($cfg, $priv);
}
} catch (Exception $e) {
die("FATAL ERROR: Invalid PRIVATE CONFIGURATION!\n");
}
}
if (!is_array($cfg)) {
die("FATAL ERROR: Invalid CONFIGURATION!\n");
}
// set DEFAULT TIME ZONE
date_default_timezone_set(
(string) ($cfg['date_default_timezone'] ?? 'Europe/Prague')
);
// set DEBUGGER
if (($_SERVER['SERVER_NAME'] ?? '') == 'localhost') { // LOCALHOST only
if (($cfg['dbg'] ?? null) === false) {
defined('DEBUG') || define('DEBUG', false); // DISABLED via configuration
}
defined('DEBUG') || define('DEBUG', true); // ENABLED for localhost
}
if (CLI === true) {
defined('DEBUG') || define('DEBUG', false); // DISABLED for CLI
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'curl') !== false) {
defined('DEBUG') || define('DEBUG', false); // DISABLED for curl
}
}
defined('DEBUG') || define('DEBUG', (bool) ($cfg['dbg'] ?? false));
if (DEBUG === true) {
// https://api.nette.org/3.0/Tracy/Debugger.html
// https://www.php.net/manual/en/errorfunc.constants.php
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) {
$address = $_SERVER['HTTP_CF_CONNECTING_IP']
?? $_SERVER['HTTP_X_FORWARDED_FOR']
?? $_SERVER['REMOTE_ADDR'];
$debug_cookie = (string) $cfg['DEBUG_COOKIE']; // private config value
Debugger::enable(
"{$debug_cookie}@{$address}", LOGS, (string) ($cfg['DEBUG_EMAIL'] ?? '')
);
} else {
// turn it ON
Debugger::enable(
(bool) ($cfg['DEBUG_DEVELOPMENT_MODE'] ?? true)
? Debugger::DEVELOPMENT : Debugger::DETECT, LOGS
);
}
}
Debugger::timer('RUN');
require_once APP . DS . 'App.php';