All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 1m57s
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Symfony\Config\DoctrineConfig;
|
|
|
|
return static function (DoctrineConfig $doctrine): void {
|
|
$driver = strtolower((string) ($_ENV['DATABASE_DRIVER'] ?? $_SERVER['DATABASE_DRIVER'] ?? 'postgres'));
|
|
$supportedDrivers = ['postgres', 'sqlite'];
|
|
|
|
if (!in_array($driver, $supportedDrivers, true)) {
|
|
throw new \InvalidArgumentException(sprintf(
|
|
'Unsupported DATABASE_DRIVER "%s". Allowed values: %s',
|
|
$driver,
|
|
implode(', ', $supportedDrivers)
|
|
));
|
|
}
|
|
|
|
$dbal = $doctrine->dbal();
|
|
$dbal->defaultConnection('default');
|
|
|
|
$connection = $dbal->connection('default');
|
|
$connection->profilingCollectBacktrace('%kernel.debug%');
|
|
$connection->useSavepoints(true);
|
|
|
|
if ('sqlite' === $driver) {
|
|
$connection->driver('pdo_sqlite');
|
|
|
|
$hasCustomPath = array_key_exists('DATABASE_SQLITE_PATH', $_ENV)
|
|
|| array_key_exists('DATABASE_SQLITE_PATH', $_SERVER);
|
|
|
|
if ($hasCustomPath) {
|
|
$connection->path('%env(resolve:DATABASE_SQLITE_PATH)%');
|
|
} else {
|
|
$connection->path('%kernel.project_dir%/var/data/database.sqlite');
|
|
}
|
|
} else {
|
|
$connection->url('%env(resolve:DATABASE_URL)%');
|
|
$connection->serverVersion('16');
|
|
$connection->charset('utf8');
|
|
}
|
|
};
|
|
|