asdasd
All checks were successful
Deploy / deploy-staging (push) Successful in 25s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-06-25 00:17:31 +02:00
parent 46111d8988
commit ac2d95fc56
140 changed files with 1168 additions and 1984 deletions

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Modules\FxRates\Infrastructure;
use App\PdoFactory;
use RuntimeException;
use PDO;
final class ConnectionFactory
{
public static function make(SettingsStore $settingsStore): PDO
{
$settings = $settingsStore->load();
$useSeparateDb = !empty($settings['use_separate_db']);
if ($useSeparateDb) {
$dbConfig = is_array($settings['db'] ?? null) ? $settings['db'] : [];
if ($dbConfig === []) {
throw new RuntimeException('Custom-Datenbank ist aktiviert, aber nicht vollstaendig konfiguriert.');
}
self::assertSupportedDriver($dbConfig);
return PdoFactory::createFromArray($dbConfig);
}
$dbConfig = app()->config()->dbConfig;
if ($dbConfig === []) {
throw new RuntimeException('Projekt-Datenbankkonfiguration fehlt in config/db_settings_basic.php.');
}
self::assertSupportedDriver($dbConfig);
return PdoFactory::createFromArray($dbConfig);
}
private static function assertSupportedDriver(array $dbConfig): void
{
$driver = strtolower((string) ($dbConfig['driver'] ?? ($dbConfig['dsn'] ?? '')));
if ($driver !== '' && !in_array($driver, ['mysql', 'pgsql', 'sqlite'], true) && !str_starts_with($driver, 'mysql:') && !str_starts_with($driver, 'pgsql:') && !str_starts_with($driver, 'sqlite:')) {
throw new RuntimeException('FX-Rates unterstuetzt aktuell MySQL/MariaDB, PostgreSQL und SQLite.');
}
}
}