|
6 | 6 |
|
7 | 7 | require_once __DIR__ . '/lib/bootstrap.php';
|
8 | 8 |
|
| 9 | +Configuration::verifyInstallation(); |
| 10 | +$customConfig = []; |
| 11 | +if (file_exists(__DIR__ . '/config.ini.php')) { |
| 12 | + $customConfig = parse_ini_file(__DIR__ . '/config.ini.php', true, INI_SCANNER_TYPED); |
| 13 | +} |
| 14 | +Configuration::loadConfiguration($customConfig, getenv()); |
| 15 | + |
| 16 | +// Consider: ini_set('error_reporting', E_ALL & ~E_DEPRECATED); |
| 17 | +date_default_timezone_set(Configuration::getConfig('system', 'timezone')); |
| 18 | + |
9 | 19 | $rssBridge = new RssBridge();
|
10 | 20 |
|
| 21 | +set_exception_handler(function (\Throwable $e) { |
| 22 | + http_response_code(500); |
| 23 | + print render(__DIR__ . '/templates/exception.html.php', ['e' => $e]); |
| 24 | + RssBridge::getLogger()->error('Uncaught Exception', ['e' => $e]); |
| 25 | + exit(1); |
| 26 | +}); |
| 27 | + |
| 28 | +set_error_handler(function ($code, $message, $file, $line) { |
| 29 | + if ((error_reporting() & $code) === 0) { |
| 30 | + return false; |
| 31 | + } |
| 32 | + // In the future, uncomment this: |
| 33 | + //throw new \ErrorException($message, 0, $code, $file, $line); |
| 34 | + $text = sprintf( |
| 35 | + '%s at %s line %s', |
| 36 | + sanitize_root($message), |
| 37 | + sanitize_root($file), |
| 38 | + $line |
| 39 | + ); |
| 40 | + RssBridge::getLogger()->warning($text); |
| 41 | +}); |
| 42 | + |
| 43 | +// There might be some fatal errors which are not caught by set_error_handler() or \Throwable. |
| 44 | +register_shutdown_function(function () { |
| 45 | + $error = error_get_last(); |
| 46 | + if ($error) { |
| 47 | + $message = sprintf( |
| 48 | + '(shutdown) %s: %s in %s line %s', |
| 49 | + $error['type'], |
| 50 | + sanitize_root($error['message']), |
| 51 | + sanitize_root($error['file']), |
| 52 | + $error['line'] |
| 53 | + ); |
| 54 | + RssBridge::getLogger()->error($message); |
| 55 | + if (Debug::isEnabled()) { |
| 56 | + print sprintf("<pre>%s</pre>\n", e($message)); |
| 57 | + } |
| 58 | + } |
| 59 | +}); |
| 60 | + |
11 | 61 | $rssBridge->main($argv ?? []);
|
0 commit comments