1111
1212namespace Symfony \Component \Cache \Adapter ;
1313
14+ use Doctrine \DBAL \ArrayParameterType ;
15+ use Doctrine \DBAL \Configuration ;
1416use Doctrine \DBAL \Connection ;
1517use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
1618use Doctrine \DBAL \DriverManager ;
1719use Doctrine \DBAL \Exception as DBALException ;
1820use Doctrine \DBAL \Exception \TableNotFoundException ;
1921use Doctrine \DBAL \ParameterType ;
22+ use Doctrine \DBAL \Schema \DefaultSchemaManagerFactory ;
2023use Doctrine \DBAL \Schema \Schema ;
24+ use Doctrine \DBAL \Tools \DsnParser ;
2125use Symfony \Component \Cache \Exception \InvalidArgumentException ;
2226use Symfony \Component \Cache \Marshaller \DefaultMarshaller ;
2327use Symfony \Component \Cache \Marshaller \MarshallerInterface ;
@@ -68,7 +72,28 @@ public function __construct($connOrDsn, string $namespace = '', int $defaultLife
6872 if (!class_exists (DriverManager::class)) {
6973 throw new InvalidArgumentException (sprintf ('Failed to parse the DSN "%s". Try running "composer require doctrine/dbal". ' , $ connOrDsn ));
7074 }
71- $ this ->conn = DriverManager::getConnection (['url ' => $ connOrDsn ]);
75+ if (class_exists (DsnParser::class)) {
76+ $ params = (new DsnParser ([
77+ 'db2 ' => 'ibm_db2 ' ,
78+ 'mssql ' => 'pdo_sqlsrv ' ,
79+ 'mysql ' => 'pdo_mysql ' ,
80+ 'mysql2 ' => 'pdo_mysql ' ,
81+ 'postgres ' => 'pdo_pgsql ' ,
82+ 'postgresql ' => 'pdo_pgsql ' ,
83+ 'pgsql ' => 'pdo_pgsql ' ,
84+ 'sqlite ' => 'pdo_sqlite ' ,
85+ 'sqlite3 ' => 'pdo_sqlite ' ,
86+ ]))->parse ($ connOrDsn );
87+ } else {
88+ $ params = ['url ' => $ connOrDsn ];
89+ }
90+
91+ $ config = new Configuration ();
92+ if (class_exists (DefaultSchemaManagerFactory::class)) {
93+ $ config ->setSchemaManagerFactory (new DefaultSchemaManagerFactory ());
94+ }
95+
96+ $ this ->conn = DriverManager::getConnection ($ params , $ config );
7297 } else {
7398 throw new \TypeError (sprintf ('Argument 1 passed to "%s()" must be "%s" or string, "%s" given. ' , __METHOD__ , Connection::class, get_debug_type ($ connOrDsn )));
7499 }
@@ -156,7 +181,7 @@ protected function doFetch(array $ids): iterable
156181 $ ids ,
157182 ], [
158183 ParameterType::INTEGER ,
159- Connection::PARAM_STR_ARRAY ,
184+ class_exists (ArrayParameterType::class) ? ArrayParameterType:: STRING : Connection::PARAM_STR_ARRAY ,
160185 ])->iterateNumeric ();
161186
162187 foreach ($ result as $ row ) {
@@ -174,7 +199,7 @@ protected function doFetch(array $ids): iterable
174199 $ expired ,
175200 ], [
176201 ParameterType::INTEGER ,
177- Connection::PARAM_STR_ARRAY ,
202+ class_exists (ArrayParameterType::class) ? ArrayParameterType:: STRING : Connection::PARAM_STR_ARRAY ,
178203 ]);
179204 }
180205 }
@@ -226,7 +251,7 @@ protected function doDelete(array $ids): bool
226251 {
227252 $ sql = "DELETE FROM $ this ->table WHERE $ this ->idCol IN (?) " ;
228253 try {
229- $ this ->conn ->executeStatement ($ sql , [array_values ($ ids )], [Connection::PARAM_STR_ARRAY ]);
254+ $ this ->conn ->executeStatement ($ sql , [array_values ($ ids )], [class_exists (ArrayParameterType::class) ? ArrayParameterType:: STRING : Connection::PARAM_STR_ARRAY ]);
230255 } catch (TableNotFoundException $ e ) {
231256 }
232257
@@ -285,35 +310,42 @@ protected function doSave(array $values, int $lifetime)
285310 $ stmt = $ this ->conn ->prepare ($ sql );
286311 }
287312
288- // $id and $data are defined later in the loop. Binding is done by reference, values are read on execution.
289313 if ('sqlsrv ' === $ platformName || 'oci ' === $ platformName ) {
290- $ stmt ->bindParam (1 , $ id );
291- $ stmt ->bindParam (2 , $ id );
292- $ stmt ->bindParam (3 , $ data , ParameterType::LARGE_OBJECT );
314+ $ bind = static function ($ id , $ data ) use ($ stmt ) {
<
CB92
tr class="diff-line-row">315+ $ stmt ->bindValue (1 , $ id );
316+ $ stmt ->bindValue (2 , $ id );
317+ $ stmt ->bindValue (3 , $ data , ParameterType::LARGE_OBJECT );
318+ $ stmt ->bindValue (6 , $ data , ParameterType::LARGE_OBJECT );
319+ };
293320 $ stmt ->bindValue (4 , $ lifetime , ParameterType::INTEGER );
294321 $ stmt ->bindValue (5 , $ now , ParameterType::INTEGER );
295- $ stmt ->bindParam (6 , $ data , ParameterType::LARGE_OBJECT );
296322 $ stmt ->bindValue (7 , $ lifetime , ParameterType::INTEGER );
297323 $ stmt ->bindValue (8 , $ now , ParameterType::INTEGER );
298324 } elseif (null !== $ platformName ) {
299- $ stmt ->bindParam (1 , $ id );
300- $ stmt ->bindParam (2 , $ data , ParameterType::LARGE_OBJECT );
325+ $ bind = static function ($ id , $ data ) use ($ stmt ) {
326+ $ stmt ->bindValue (1 , $ id );
327+ $ stmt ->bindValue (2 , $ data , ParameterType::LARGE_OBJECT );
328+ };
301329 $ stmt ->bindValue (3 , $ lifetime , ParameterType::INTEGER );
302330 $ stmt ->bindValue (4 , $ now , ParameterType::INTEGER );
303331 } else {
304- $ stmt ->bindParam (1 , $ data , ParameterType::LARGE_OBJECT );
305332 $ stmt ->bindValue (2 , $ lifetime , ParameterType::INTEGER );
306333 $ stmt ->bindValue (3 , $ now , ParameterType::INTEGER );
307- $ stmt ->bindParam (4 , $ id );
308334
309335 $ insertStmt = $ this ->conn ->prepare ($ insertSql );
310- $ insertStmt ->bindParam (1 , $ id );
311- $ insertStmt ->bindParam (2 , $ data , ParameterType::LARGE_OBJECT );
312336 $ insertStmt ->bindValue (3 , $ lifetime , ParameterType::INTEGER );
313337 $ insertStmt ->bindValue (4 , $ now , ParameterType::INTEGER );
338+
339+ $ bind = static function ($ id , $ data ) use ($ stmt , $ insertStmt ) {
340+ $ stmt ->bindValue (1 , $ data , ParameterType::LARGE_OBJECT );
341+ $ stmt ->bindValue (4
402E
, $ id );
342+ $ insertStmt ->bindValue (1 , $ id );
343+ $ insertStmt ->bindValue (2 , $ data , ParameterType::LARGE_OBJECT );
344+ };
314345 }
315346
316347 foreach ($ values as $ id => $ data ) {
348+ $ bind ($ id , $ data );
317349 try {
318350 $ rowCount = $ stmt ->executeStatement ();
319351 } catch (TableNotFoundException $ e ) {
0 commit comments