Skip to content

Commit 3cedf31

Browse files
committed
Deprecate driver name aliases
1 parent 2ab7855 commit 3cedf31

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ awareness about deprecated code.
88

99
# Upgrade to 3.5
1010

11+
## Deprecated driver name aliases.
12+
13+
Relying on driver name aliases in connection parameters has been deprecated. Use the actual driver names instead.
14+
1115
## Deprecated "unique" and "check" column properties.
1216

1317
The "unique" and "check" column properties have been deprecated. Use unique constraints to define unique columns.

docs/en/reference/configuration.rst

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,14 @@ The path after the authority part represents the name of the
4949
database, sans the leading slash. Any query parameters are used as
5050
additional connection parameters.
5151

52-
The scheme names representing the drivers are either the regular
53-
driver names (see below) with any underscores in their name replaced
54-
with a hyphen (to make them legal in URL scheme names), or one of the
55-
following simplified driver names that serve as aliases:
56-
57-
- ``db2``: alias for ``ibm_db2``
58-
- ``mssql``: alias for ``pdo_sqlsrv``
59-
- ``mysql``/``mysql2``: alias for ``pdo_mysql``
60-
- ``pgsql``/``postgres``/``postgresql``: alias for ``pdo_pgsql``
61-
- ``sqlite``/``sqlite3``: alias for ``pdo_sqlite``
62-
63-
For example, to connect to a "foo" MySQL DB using the ``pdo_mysql``
52+
The scheme names representing the drivers are the driver names
53+
with any underscores in their name replaced with a hyphen
54+
(to make them legal in URL scheme names).
55+
56+
For example, to connect to a "foo" MySQL database using the ``pdo_mysql``
6457
driver on localhost port 4486 with the "charset" option set to ``utf8mb4``,
6558
you would use the following URL::
6659

67-
mysql://localhost:4486/foo?charset=utf8mb4
68-
69-
This is identical to the following connection string using the
70-
full driver name::
71-
7260
pdo-mysql://localhost:4486/foo?charset=utf8mb4
7361

7462
In the example above, mind the dashes instead of the
@@ -79,28 +67,28 @@ URL is obviously irrelevant and thus can be omitted. The path part
7967
of the URL is, like for all other drivers, stripped of its leading
8068
slash, resulting in a relative file name for the database::
8169

82-
sqlite:///somedb.sqlite
70+
pdo-sqlite:///somedb.sqlite
8371

8472
This would access ``somedb.sqlite`` in the current working directory
8573
and is identical to the following::
8674

87-
sqlite://ignored:ignored@ignored:1234/somedb.sqlite
75+
pdo-sqlite://ignored:ignored@ignored:1234/somedb.sqlite
8876

8977
To specify an absolute file path, e.g. ``/usr/local/var/db.sqlite``,
9078
simply use that as the database name, which results in two leading
9179
slashes for the path part of the URL, and four slashes in total after
9280
the URL scheme name and its following colon::
9381

94-
sqlite:////usr/local/var/db.sqlite
82+
pdo-sqlite:////usr/local/var/db.sqlite
9583

9684
Which is, again, identical to supplying ignored user/pass/authority::
9785

98-
sqlite://notused:inthis@case//usr/local/var/db.sqlite
86+
pdo-sqlite://notused:inthis@case//usr/local/var/db.sqlite
9987

10088
To connect to an in-memory SQLite instance, use ``:memory:`` as the
10189
database name::
10290

103-
sqlite:///:memory:
91+
pdo-sqlite:///:memory:
10492

10593
.. note::
10694

src/DriverManager.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Driver\OCI8;
99
use Doctrine\DBAL\Driver\PDO;
1010
use Doctrine\DBAL\Driver\SQLSrv;
11+
use Doctrine\Deprecations\Deprecation;
1112

1213
use function array_keys;
1314
use function array_merge;
@@ -92,6 +93,8 @@ final class DriverManager
9293
/**
9394
* List of URL schemes from a database URL and their mappings to driver.
9495
*
96+
* @deprecated Use actual driver names instead.
97+
*
9598
* @var string[]
9699
*/
97100
private static array $driverSchemeAliases = [
@@ -451,11 +454,25 @@ private static function parseDatabaseUrlScheme(?string $scheme, array $params):
451454
// URL schemes must not contain underscores, but dashes are ok
452455
$driver = str_replace('-', '_', $scheme);
453456

454-
// The requested driver from the URL scheme takes precedence over the
455-
// default driver from the connection parameters. If the driver is
456-
// an alias (e.g. "postgres"), map it to the actual name ("pdo-pgsql").
457+
// If the driver is an alias (e.g. "postgres"), map it to the actual name ("pdo-pgsql").
457458
// Otherwise, let checkParams decide later if the driver exists.
458-
$params['driver'] = self::$driverSchemeAliases[$driver] ?? $driver;
459+
if (isset(self::$driverSchemeAliases[$driver])) {
460+
$actualDriver = self::$driverSchemeAliases[$driver];
461+
462+
Deprecation::trigger(
463+
'doctrine/dbal',
464+
'https://github.com/doctrine/dbal/pull/5697',
465+
'Relying on driver name aliases is deprecated. Use %s instead of %s.',
466+
str_replace('_', '-', $actualDriver),
467+
$driver,
468+
);
469+
470+
$driver = $actualDriver;
471+
}
472+
473+
// The requested driver from the URL scheme takes precedence over the
474+
// default driver from the connection parameters.
475+
$params['driver'] = $driver;
459476

460477
return $params;
461478
}

0 commit comments

Comments
 (0)