<?php
define('APP_ROOT', __DIR__ . '/html');
define('FUNCTIONS_ROOT', __DIR__ . '/functions');
define('STORAGE_ROOT', __DIR__ . '/storage');
define('WECKER_LOG_DIR', __DIR__ . '/logs');
define('DatabaseDEBUG', true);
define('LogDEBUG', true);

// Apache-Error-/Access-Log (für Debug-Errorlog-Viewer)
if (!defined('DEBUG_ERROR_LOG_PATH')) {
    define('DEBUG_ERROR_LOG_PATH', WECKER_LOG_DIR . '/error.log');
}

// DB-Zugangsdaten (werden beim Install durch setup_db.sh gesetzt)
$dsn  = 'mysql:host=WECKER_DB_HOST;port=WECKER_DB_PORT;dbname=WECKER_DB_NAME;charset=utf8mb4';
$user = 'WECKER_DB_USER';
$pass = 'WECKER_DB_PASS';

try {
    $pdo = new PDO(
        $dsn,
        $user,
        $pass,
        [
            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES   => false,
        ]
    );
    $GLOBALS['pdo'] = $pdo;
} catch (Throwable $e) {
    error_log('[DB CONNECT ERROR] ' . $e->getMessage() . ' | DSN=' . $dsn);
    http_response_code(500);
    require APP_ROOT . '/errors/500.php';
    die;    
}
