22
33namespace Doctrine \Bundle \DoctrineBundle ;
44
5- use Doctrine \Common \EventManager ;
65use Doctrine \DBAL \Configuration ;
76use Doctrine \DBAL \Connection ;
87use Doctrine \DBAL \Connection \StaticServerVersionProvider ;
1716use Doctrine \DBAL \Platforms \AbstractPlatform ;
1817use Doctrine \DBAL \Tools \DsnParser ;
1918use Doctrine \DBAL \Types \Type ;
20- use Doctrine \Deprecations \Deprecation ;
21- use InvalidArgumentException ;
2219
2320use function array_merge ;
2421use function class_exists ;
25- use function func_num_args ;
26- use function is_array ;
2722use function is_subclass_of ;
28- use function method_exists ;
2923use function trigger_deprecation ;
3024
3125use const PHP_EOL ;
@@ -62,52 +56,17 @@ public function __construct(
6256 /**
6357 * Create a connection by name.
6458 *
65- * @param mixed[] $params
66- * @param EventManager|array<string, string>|null $eventManagerOrMappingTypes
67- * @param array<string, string> $deprecatedMappingTypes
59+ * @param mixed[] $params
60+ * @param array<string, string> $mappingTypes
6861 * @phpstan-param Params $params
6962 *
7063 * @return Connection
71- *
72- * @no-named-arguments
7364 */
7465 public function createConnection (
7566 array $ params ,
7667 Configuration |null $ config = null ,
77- EventManager |array |null $ eventManagerOrMappingTypes = [],
78- array $ deprecatedMappingTypes = [],
68+ array $ mappingTypes = [],
7969 ) {
80- if (! method_exists (Connection::class, 'getEventManager ' ) && $ eventManagerOrMappingTypes instanceof EventManager) {
81- throw new InvalidArgumentException ('Passing an EventManager instance is not supported with DBAL > 3 ' );
82- }
83-
84- if (is_array ($ eventManagerOrMappingTypes ) && func_num_args () === 4 ) {
85- throw new InvalidArgumentException ('Passing mapping types both as 3rd and 4th argument makes no sense. ' );
86- }
87-
88- if ($ eventManagerOrMappingTypes instanceof EventManager) {
89- // DBAL 3
90- $ eventManager = $ eventManagerOrMappingTypes ;
91- $ mappingTypes = $ deprecatedMappingTypes ;
92- } elseif (is_array ($ eventManagerOrMappingTypes )) {
93- // Future signature
94- $ eventManager = null ;
95- $ mappingTypes = $ eventManagerOrMappingTypes ;
96- } else {
97- // Legacy signature
98- if (! method_exists (Connection::class, 'getEventManager ' )) {
99- Deprecation::trigger (
100- 'doctrine/doctrine-bundle ' ,
101- 'https://github.com/doctrine/DoctrineBundle/pull/1976 ' ,
102- 'Passing mapping types as 4th argument to %s is deprecated when using DBAL 4 and will not be supported in version 3.0 of the bundle. Pass them as 3rd argument instead. ' ,
103- __METHOD__ ,
104- );
105- }
106-
107- $ eventManager = null ;
108- $ mappingTypes = $ deprecatedMappingTypes ;
109- }
110-
11170 if (! $ this ->initialized ) {
11271 $ this ->initializeTypes ();
11372 }
@@ -151,16 +110,12 @@ public function createConnection(
151110 $ params ['wrapperClass ' ] = null ;
152111 }
153112
154- $ connection = DriverManager::getConnection (... array_merge ([ $ params , $ config], $ eventManager ? [ $ eventManager ] : []) );
113+ $ connection = DriverManager::getConnection ($ params , $ config );
155114 $ params = $ this ->addDatabaseSuffix (array_merge ($ connection ->getParams (), $ overriddenOptions ));
156115 $ driver = $ connection ->getDriver ();
157- /** @phpstan-ignore arguments.count (DBAL < 4.x doesn't accept an argument) */
158- $ platform = $ driver ->getDatabasePlatform (
159- ...(class_exists (StaticServerVersionProvider::class)
160- ? [new StaticServerVersionProvider ($ params ['serverVersion ' ] ?? $ params ['primary ' ]['serverVersion ' ] ?? '' )]
161- : []
162- ),
163- );
116+ $ platform = $ driver ->getDatabasePlatform (new StaticServerVersionProvider (
117+ $ params ['serverVersion ' ] ?? $ params ['primary ' ]['serverVersion ' ] ?? '' ,
118+ ));
164119
165120 if (! isset ($ params ['charset ' ])) {
166121 if ($ platform instanceof AbstractMySQLPlatform) {
@@ -179,9 +134,9 @@ public function createConnection(
179134 $ wrapperClass = Connection::class;
180135 }
181136
182- $ connection = new $ wrapperClass ($ params , $ driver , $ config, $ eventManager );
137+ $ connection = new $ wrapperClass ($ params , $ driver , $ config );
183138 } else {
184- $ connection = DriverManager::getConnection (... array_merge ([ $ params , $ config], $ eventManager ? [ $ eventManager ] : []) );
139+ $ connection = DriverManager::getConnection ($ params , $ config );
185140 }
186141
187142 if (! empty ($ mappingTypes )) {
@@ -209,10 +164,7 @@ private function getDatabasePlatform(Connection $connection): AbstractPlatform
209164 try {
210165 return $ connection ->getDatabasePlatform ();
211166 } catch (DriverException $ driverException ) {
212- $ class = class_exists (DBALException::class) ? DBALException::class : ConnectionException::class;
213-
214- /* @phpstan-ignore new.interface */
215- throw new $ class (
167+ throw new ConnectionException (
216168 'An exception occurred while establishing a connection to figure out your platform version. ' . PHP_EOL .
217169 "You can circumvent this by setting a 'server_version' configuration value " . PHP_EOL . PHP_EOL .
218170 'For further information have a look at: ' . PHP_EOL .
@@ -305,11 +257,7 @@ private function parseDatabaseUrl(array $params): array
305257 // If a schemeless connection URL is given, we require a default driver or default custom driver
306258 // as connection parameter.
307259 if (! isset ($ params ['driverClass ' ]) && ! isset ($ params ['driver ' ])) {
308- if (class_exists (DriverRequired::class)) {
309- throw DriverRequired::new ($ params ['url ' ]);
310- }
311-
312- throw DBALException::driverRequired ($ params ['url ' ]);
260+ throw DriverRequired::new ($ params ['url ' ]);
313261 }
314262
315263 unset($ params ['url ' ]);
0 commit comments