renew
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Core\Autoloader;
|
||||
use App\Core\Csrf;
|
||||
use App\Core\Database;
|
||||
use App\Core\DatabaseSqlite;
|
||||
use App\Core\Env;
|
||||
use App\Core\Session;
|
||||
use App\Core\View;
|
||||
|
||||
$rootPath = dirname(__DIR__);
|
||||
|
||||
require_once $rootPath . '/app/Support/helpers.php';
|
||||
require_once $rootPath . '/app/Core/Autoloader.php';
|
||||
|
||||
Autoloader::register($rootPath);
|
||||
Env::load($rootPath . '/.env');
|
||||
|
||||
$config = require $rootPath . '/config/app.php';
|
||||
|
||||
date_default_timezone_set($config['timezone']);
|
||||
|
||||
ini_set('session.use_strict_mode', '1');
|
||||
ini_set('session.use_only_cookies', '1');
|
||||
ini_set('session.use_trans_sid', '0');
|
||||
session_name('kaffeekasse_session');
|
||||
|
||||
$session = new Session();
|
||||
$session->start();
|
||||
|
||||
$csrf = new Csrf($session);
|
||||
|
||||
// SQLite oder MySQL basierend auf DB_HOST Konfiguration und verfügbaren Treibern
|
||||
if (($config['db']['host'] ?? '') === 'sqlite') {
|
||||
$database = new DatabaseSqlite(['path' => $config['db']['name']]);
|
||||
} else {
|
||||
// Prüfe ob MySQL PDO Treiber verfügbar ist
|
||||
$availableDrivers = PDO::getAvailableDrivers();
|
||||
if (in_array('mysql', $availableDrivers)) {
|
||||
try {
|
||||
$database = new Database($config['db']);
|
||||
// Teste die Verbindung
|
||||
$database->pdo();
|
||||
} catch (\Throwable $e) {
|
||||
// Fallback zu SQLite wenn MySQL-Verbindung fehlschlägt
|
||||
error_log('MySQL connection failed, falling back to SQLite: ' . $e->getMessage());
|
||||
$database = new DatabaseSqlite(['path' => $rootPath . '/storage/database.sqlite']);
|
||||
}
|
||||
} else {
|
||||
// Fallback zu SQLite wenn MySQL-Treiber nicht verfügbar
|
||||
error_log('MySQL PDO driver not available, using SQLite');
|
||||
$database = new DatabaseSqlite(['path' => $rootPath . '/storage/database.sqlite']);
|
||||
}
|
||||
}
|
||||
|
||||
$view = new View($rootPath, [
|
||||
'config' => $config,
|
||||
'session' => $session,
|
||||
'csrf' => $csrf,
|
||||
]);
|
||||
|
||||
return [
|
||||
'rootPath' => $rootPath,
|
||||
'config' => $config,
|
||||
'session' => $session,
|
||||
'csrf' => $csrf,
|
||||
'database' => $database,
|
||||
'view' => $view,
|
||||
];
|
||||
Reference in New Issue
Block a user