asdasd
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user