From 8a77771a91138f45e992e4c140d7f90bb9a4f41e Mon Sep 17 00:00:00 2001 From: clementzarch Date: Thu, 18 May 2023 14:10:35 +0200 Subject: [PATCH] always create PDOPool.php, because it is used both in "shared" and "unique" connections (as seen in src/Builder/Connection) --- src/Factory/Connection.php | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Factory/Connection.php b/src/Factory/Connection.php index afc4c19..788762d 100644 --- a/src/Factory/Connection.php +++ b/src/Factory/Connection.php @@ -84,27 +84,25 @@ public function compile(array $config): SQL\Factory\Repository\Connection $repository = new SQL\Factory\Repository\Connection($connection); - if (\array_key_exists('shared', $config) && true === $config['shared']) { - $repository->addFiles(new File('PDOPool.php', new InMemory(<<generatedNamespace}; - final class PDOPool { - private static array \$connections = []; - public static function unique(string \$dsn, ?string \$username = null, ?string \$password = null, \$options = []): \\PDO { - return new \\PDO(\$dsn, \$username, \$password, \$options); - } - public static function shared(string \$dsn, ?string \$username = null, ?string \$password = null, \$options = []): \\PDO { - if (isset(self::\$connections[\$dsn])) { - return self::\$connections[\$dsn]; - } - - return self::\$connections[\$dsn] = self::unique(\$dsn, \$username, \$password, \$options); + $repository->addFiles(new File('PDOPool.php', new InMemory(<<generatedNamespace}; + final class PDOPool { + private static array \$connections = []; + public static function unique(string \$dsn, ?string \$username = null, ?string \$password = null, \$options = []): \\PDO { + return new \\PDO(\$dsn, \$username, \$password, \$options); + } + public static function shared(string \$dsn, ?string \$username = null, ?string \$password = null, \$options = []): \\PDO { + if (isset(self::\$connections[\$dsn])) { + return self::\$connections[\$dsn]; } + + return self::\$connections[\$dsn] = self::unique(\$dsn, \$username, \$password, \$options); } - PHP - ))); - } + } + PHP + ))); return $repository; }