File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Doctrine \DBAL \Tools ;
4
4
5
+ use Doctrine \DBAL \Driver ;
5
6
use Doctrine \DBAL \DriverManager ;
6
7
use Doctrine \DBAL \Exception \MalformedDsnException ;
7
8
use SensitiveParameter ;
8
9
9
10
use function array_merge ;
10
11
use function assert ;
12
+ use function is_a ;
11
13
use function is_string ;
12
14
use function parse_str ;
13
15
use function parse_url ;
20
22
/** @psalm-import-type Params from DriverManager */
21
23
final class DsnParser
22
24
{
23
- /** @var array<string, string> */
25
+ /** @var array<string, string|class-string<Driver> > */
24
26
private array $ schemeMapping ;
25
27
26
- /** @param array<string, string> $schemeMapping An array used to map DSN schemes to DBAL drivers */
28
+ /** @param array<string, string|class-string<Driver> > $schemeMapping An array used to map DSN schemes to DBAL drivers */
27
29
public function __construct (array $ schemeMapping = [])
28
30
{
29
31
$ this ->schemeMapping = $ schemeMapping ;
@@ -78,6 +80,11 @@ public function parse(
78
80
$ params ['password ' ] = $ url ['pass ' ];
79
81
}
80
82
83
+ if (isset ($ params ['driver ' ]) && is_a ($ params ['driver ' ], Driver::class, true )) {
84
+ $ params ['driverClass ' ] = $ params ['driver ' ];
85
+ unset($ params ['driver ' ]);
86
+ }
87
+
81
88
$ params = $ this ->parseDatabaseUrlPath ($ url , $ params );
82
89
$ params = $ this ->parseDatabaseUrlQuery ($ url , $ params );
83
90
Original file line number Diff line number Diff line change 2
2
3
3
namespace Doctrine \DBAL \Tests \Tools ;
4
4
5
+ use Doctrine \DBAL \Driver ;
5
6
use Doctrine \DBAL \DriverManager ;
6
7
use Doctrine \DBAL \Tools \DsnParser ;
7
8
use PHPUnit \Framework \TestCase ;
8
9
10
+ use function get_class ;
9
11
use function ksort ;
10
12
11
13
/** @psalm-import-type Params from DriverManager */
@@ -172,4 +174,22 @@ public function databaseUrls(): iterable
172
174
],
173
175
];
174
176
}
177
+
178
+ public function testDriverClassScheme (): void
179
+ {
180
+ $ driverClass = get_class ($ this ->createMock (Driver::class));
181
+ $ parser = new DsnParser (['custom ' => $ driverClass ]);
182
+ $ actual = $ parser ->parse ('custom://foo:bar@localhost/baz ' );
183
+
184
+ self ::assertSame (
185
+ [
186
+ 'host ' => 'localhost ' ,
187
+ 'user ' => 'foo ' ,
188
+ 'password ' => 'bar ' ,
189
+ 'driverClass ' => $ driverClass ,
190
+ 'dbname ' => 'baz ' ,
191
+ ],
192
+ $ actual ,
193
+ );
194
+ }
175
195
}
You can’t perform that action at this time.
0 commit comments