@@ -45,8 +45,17 @@ public function createConnection(array $params, Configuration $config = null, Ev
45
45
$ this ->initializeTypes ();
46
46
}
47
47
48
- if (! isset ($ params ['pdo ' ]) && ! isset ($ params ['charset ' ])) {
49
- $ wrapperClass = null ;
48
+ $ allowOverrideUrl = $ params ['override_url ' ] ?? false ;
49
+ unset($ params ['override_url ' ]);
50
+
51
+ if (! $ allowOverrideUrl ) {
52
+ $ this ->triggerUrlOverrideDeprecation ();
53
+ }
54
+
55
+ if (! isset ($ params ['pdo ' ]) && (! isset ($ params ['charset ' ]) || $ allowOverrideUrl )) {
56
+ $ originalParams = $ params ;
57
+ $ wrapperClass = null ;
58
+
50
59
if (isset ($ params ['wrapperClass ' ])) {
51
60
if (! is_subclass_of ($ params ['wrapperClass ' ], Connection::class)) {
52
61
if (class_exists (DBALException::class)) {
@@ -64,6 +73,24 @@ public function createConnection(array $params, Configuration $config = null, Ev
64
73
$ params = $ connection ->getParams ();
65
74
$ driver = $ connection ->getDriver ();
66
75
76
+ if ($ allowOverrideUrl ) {
77
+ $ supportedOverrideParams = [
78
+ 'dbname ' ,
79
+ 'host ' ,
80
+ 'port ' ,
81
+ 'user ' ,
82
+ 'password ' ,
83
+ ];
84
+
85
+ foreach ($ supportedOverrideParams as $ paramKey ) {
86
+ if (! isset ($ originalParams [$ paramKey ])) {
87
+ continue ;
88
+ }
89
+
90
+ $ params [$ paramKey ] = $ originalParams [$ paramKey ];
91
+ }
92
+ }
93
+
67
94
if ($ driver instanceof AbstractMySQLDriver) {
68
95
$ params ['charset ' ] = 'utf8mb4 ' ;
69
96
@@ -138,4 +165,17 @@ private function initializeTypes(): void
138
165
139
166
$ this ->initialized = true ;
140
167
}
168
+
169
+ private function triggerUrlOverrideDeprecation (): void
170
+ {
171
+ $ deprecationMessage = 'Setting doctrine.dbal.override_url to true allows you to override the dsn parameters set in doctrine.dbal.url. This will be the default behavior in future versions. ' ;
172
+
173
+ if (function_exists ('trigger_deprecation ' )) {
174
+ trigger_deprecation ('doctrine/DoctrineBundle ' , '2.3.0 ' , $ deprecationMessage );
175
+
176
+ return ;
177
+ }
178
+
179
+ @trigger_error ($ deprecationMessage , E_USER_DEPRECATED );
180
+ }
141
181
}
0 commit comments