58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
|
|
<?php
|
|||
|
|
declare(strict_types=1);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Drink it cold – Bootstrap.
|
|||
|
|
*
|
|||
|
|
* Lädt Konfiguration, Datenbank, Session und Helfer. Die Konfiguration mit
|
|||
|
|
* Zugangsdaten liegt in app/config.local.php und wird beim Deployment erzeugt.
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
define('DIC_ROOT', dirname(__DIR__));
|
|||
|
|
define('DIC_APP', __DIR__);
|
|||
|
|
|
|||
|
|
$configFile = DIC_APP . '/config.local.php';
|
|||
|
|
if (!is_file($configFile)) {
|
|||
|
|
http_response_code(500);
|
|||
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|||
|
|
echo "Die Anwendung ist noch nicht konfiguriert (app/config.local.php fehlt).\n";
|
|||
|
|
exit;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$GLOBALS['dic_config'] = require $configFile;
|
|||
|
|
|
|||
|
|
date_default_timezone_set('Europe/Berlin');
|
|||
|
|
ini_set('display_errors', '0');
|
|||
|
|
ini_set('log_errors', '1');
|
|||
|
|
|
|||
|
|
require DIC_APP . '/util.php';
|
|||
|
|
require DIC_APP . '/db.php';
|
|||
|
|
require DIC_APP . '/auth.php';
|
|||
|
|
require DIC_APP . '/data.php';
|
|||
|
|
require DIC_APP . '/mail.php';
|
|||
|
|
require DIC_APP . '/pages.php';
|
|||
|
|
require DIC_APP . '/admin.php';
|
|||
|
|
|
|||
|
|
$storage = (string) config('app.storage_path', DIC_ROOT . '/storage');
|
|||
|
|
if (is_dir($storage) && is_dir($storage . '/logs') && is_writable($storage . '/logs')) {
|
|||
|
|
ini_set('error_log', $storage . '/logs/php.log');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
set_exception_handler(static function (Throwable $error): void {
|
|||
|
|
error_log('Drink it cold: ' . $error::class . ': ' . $error->getMessage() . ' in ' . $error->getFile() . ':' . $error->getLine());
|
|||
|
|
if (function_exists('wants_json') && wants_json()) {
|
|||
|
|
json_response(['error' => ['code' => 'server_error', 'message' => 'Interner Fehler.']], 500);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
http_response_code(500);
|
|||
|
|
header('Content-Type: text/html; charset=utf-8');
|
|||
|
|
echo '<!doctype html><meta charset="utf-8"><title>Fehler 500</title>'
|
|||
|
|
. '<body style="font-family:system-ui;background:#f4f9fe;color:#0e1b26;padding:2rem">'
|
|||
|
|
. '<h1>Interner Fehler</h1><p>Bitte später erneut versuchen.</p></body>';
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (PHP_SAPI !== 'cli') {
|
|||
|
|
security_headers();
|
|||
|
|
start_session();
|
|||
|
|
}
|