This commit is contained in:
2026-01-12 22:38:08 +01:00
parent 239c2605d9
commit 771b85eb6c

View File

@@ -31,11 +31,62 @@ use App\App;
$appConfig = App::get()->config(); $appConfig = App::get()->config();
$dbConfig = $appConfig->db ?? []; $dbConfig = $appConfig->db ?? [];
function bridgeResolveDsn(array $dbConfig): string
{
$dsn = (string)($dbConfig['dsn'] ?? '');
if ($dsn !== '') {
return $dsn;
}
$driver = (string)($dbConfig['driver'] ?? '');
if ($driver === '') {
return '';
}
return match ($driver) {
'mysql' => (function () use ($dbConfig): string {
$dbname = (string)($dbConfig['dbname'] ?? '');
if ($dbname === '') {
return '';
}
$charset = (string)($dbConfig['charset'] ?? 'utf8mb4');
if (!empty($dbConfig['unix_socket'])) {
return sprintf(
'mysql:unix_socket=%s;dbname=%s;charset=%s',
(string)$dbConfig['unix_socket'],
$dbname,
$charset
);
}
$host = (string)($dbConfig['host'] ?? 'localhost');
$port = (int)($dbConfig['port'] ?? 3306);
return sprintf('mysql:host=%s;port=%d;dbname=%s;charset=%s', $host, $port, $dbname, $charset);
})(),
'pgsql' => (function () use ($dbConfig): string {
$dbname = (string)($dbConfig['dbname'] ?? '');
if ($dbname === '') {
return '';
}
$host = (string)($dbConfig['host'] ?? 'localhost');
$port = (int)($dbConfig['port'] ?? 5432);
return sprintf('pgsql:host=%s;port=%d;dbname=%s', $host, $port, $dbname);
})(),
'sqlite' => (function () use ($dbConfig): string {
$path = (string)($dbConfig['path'] ?? '');
if ($path === '') {
$path = ':memory:';
}
return 'sqlite:' . $path;
})(),
default => '',
};
}
// 2) Bridge-spezifische Konfiguration auf Basis der App-Config // 2) Bridge-spezifische Konfiguration auf Basis der App-Config
$bridgeConfig = [ $bridgeConfig = [
'token' => getenv('EMAILTEMPLATE_BRIDGE_TOKEN') ?: 'kgIqdL9aNWsFWy6mhSRpnuLc1EbZ62sGCcJAwjjlqqznEGE13szhksWUan0cEdjE', 'token' => getenv('EMAILTEMPLATE_BRIDGE_TOKEN') ?: 'kgIqdL9aNWsFWy6mhSRpnuLc1EbZ62sGCcJAwjjlqqznEGE13szhksWUan0cEdjE',
'db' => [ 'db' => [
'dsn' => getenv('EMAILTEMPLATE_BRIDGE_DSN') ?: ($dbConfig['dsn'] ?? ''), 'dsn' => getenv('EMAILTEMPLATE_BRIDGE_DSN') ?: bridgeResolveDsn($dbConfig),
'user' => getenv('EMAILTEMPLATE_BRIDGE_DB_USER') ?: ($dbConfig['user'] ?? ''), 'user' => getenv('EMAILTEMPLATE_BRIDGE_DB_USER') ?: ($dbConfig['user'] ?? ''),
'pass' => getenv('EMAILTEMPLATE_BRIDGE_DB_PASS') ?: ($dbConfig['password'] ?? ''), 'pass' => getenv('EMAILTEMPLATE_BRIDGE_DB_PASS') ?: ($dbConfig['password'] ?? ''),
'options' => $dbConfig['options'] ?? [ 'options' => $dbConfig['options'] ?? [
@@ -96,6 +147,10 @@ function bridgeDb(array $config): PDO
return $pdo; return $pdo;
} }
if (empty($config['db']['dsn'])) {
bridgeRespond(['ok' => false, 'error' => 'DB DSN not configured'], 500);
}
try { try {
$pdo = new PDO( $pdo = new PDO(
$config['db']['dsn'], $config['db']['dsn'],