2016-08-06 13:40:31 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-02-26 22:01:16 +03:00
|
|
|
use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository;
|
2022-01-20 22:16:37 +03:00
|
|
|
use Shlinkio\Shlink\Core\Config\EnvVars;
|
2021-01-09 12:56:02 +03:00
|
|
|
|
2021-08-07 12:05:20 +03:00
|
|
|
use function Functional\contains;
|
|
|
|
|
|
|
|
return (static function (): array {
|
2022-01-20 22:16:37 +03:00
|
|
|
$driver = EnvVars::DB_DRIVER()->loadFromEnv();
|
2021-08-07 12:05:20 +03:00
|
|
|
$isMysqlCompatible = contains(['maria', 'mysql'], $driver);
|
2016-08-06 13:40:31 +03:00
|
|
|
|
2021-08-07 12:05:20 +03:00
|
|
|
$resolveDriver = static fn () => match ($driver) {
|
|
|
|
'postgres' => 'pdo_pgsql',
|
|
|
|
'mssql' => 'pdo_sqlsrv',
|
|
|
|
default => 'pdo_mysql',
|
|
|
|
};
|
|
|
|
$resolveDefaultPort = static fn () => match ($driver) {
|
|
|
|
'postgres' => '5432',
|
|
|
|
'mssql' => '1433',
|
|
|
|
default => '3306',
|
|
|
|
};
|
2022-01-10 15:04:16 +03:00
|
|
|
$resolveCharset = static fn () => match ($driver) {
|
|
|
|
// This does not determine charsets or collations in tables or columns, but the charset used in the data
|
|
|
|
// flowing in the connection, so it has to match what has been set in the database.
|
|
|
|
'maria', 'mysql' => 'utf8mb4',
|
|
|
|
'postgres' => 'utf8',
|
|
|
|
default => null,
|
|
|
|
};
|
2022-01-01 20:40:48 +03:00
|
|
|
$resolveConnection = static fn () => match ($driver) {
|
|
|
|
null, 'sqlite' => [
|
2021-08-07 12:05:20 +03:00
|
|
|
'driver' => 'pdo_sqlite',
|
|
|
|
'path' => 'data/database.sqlite',
|
2016-08-06 13:40:31 +03:00
|
|
|
],
|
2021-08-07 12:05:20 +03:00
|
|
|
default => [
|
|
|
|
'driver' => $resolveDriver(),
|
2022-01-20 22:16:37 +03:00
|
|
|
'dbname' => EnvVars::DB_NAME()->loadFromEnv('shlink'),
|
|
|
|
'user' => EnvVars::DB_USER()->loadFromEnv(),
|
|
|
|
'password' => EnvVars::DB_PASSWORD()->loadFromEnv(),
|
|
|
|
'host' => EnvVars::DB_HOST()->loadFromEnv(EnvVars::DB_UNIX_SOCKET()->loadFromEnv()),
|
|
|
|
'port' => EnvVars::DB_PORT()->loadFromEnv($resolveDefaultPort()),
|
|
|
|
'unix_socket' => $isMysqlCompatible ? EnvVars::DB_UNIX_SOCKET()->loadFromEnv() : null,
|
2022-01-10 15:04:16 +03:00
|
|
|
'charset' => $resolveCharset(),
|
2016-08-06 13:40:31 +03:00
|
|
|
],
|
2021-08-07 12:05:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'entity_manager' => [
|
|
|
|
'orm' => [
|
|
|
|
'proxies_dir' => 'data/proxies',
|
|
|
|
'load_mappings_using_functional_style' => true,
|
|
|
|
'default_repository_classname' => EntitySpecificationRepository::class,
|
|
|
|
],
|
|
|
|
'connection' => $resolveConnection(),
|
|
|
|
],
|
2016-08-06 13:40:31 +03:00
|
|
|
|
2021-08-07 12:05:20 +03:00
|
|
|
];
|
|
|
|
})();
|