From c33f8d0ea2f1787c89ea6c39bf66804f4e174cc0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 15 Mar 2024 14:27:02 +0100 Subject: [PATCH] Cast database credentials to string when read from the env --- config/autoload/entity-manager.global.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config/autoload/entity-manager.global.php b/config/autoload/entity-manager.global.php index 849c91af..3eb43edf 100644 --- a/config/autoload/entity-manager.global.php +++ b/config/autoload/entity-manager.global.php @@ -16,6 +16,10 @@ return (static function (): array { 'mssql' => 'pdo_sqlsrv', default => 'pdo_mysql', }; + $readCredentialAsString = static function (EnvVars $envVar): string|null { + $value = $envVar->loadFromEnv(); + return $value === null ? null : (string) $value; + }; $resolveDefaultPort = static fn () => match ($driver) { 'postgres' => '5432', 'mssql' => '1433', @@ -28,6 +32,7 @@ return (static function (): array { 'postgres' => 'utf8', default => null, }; + $resolveConnection = static fn () => match ($driver) { null, 'sqlite' => [ 'driver' => 'pdo_sqlite', @@ -36,8 +41,8 @@ return (static function (): array { default => [ 'driver' => $resolveDriver(), 'dbname' => EnvVars::DB_NAME->loadFromEnv('shlink'), - 'user' => EnvVars::DB_USER->loadFromEnv(), - 'password' => EnvVars::DB_PASSWORD->loadFromEnv(), + 'user' => $readCredentialAsString(EnvVars::DB_USER), + 'password' => $readCredentialAsString(EnvVars::DB_PASSWORD), '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,