diff --git a/UPGRADE.md b/UPGRADE.md index 4b39948eca7..a8333dbff9b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,10 @@ awareness about deprecated code. # Upgrade to 4.0 +## BC BREAK: removed support for driver name aliases. + +Driver name aliases are no longer supported. + ## BC BREAK: removed support for the "platform" parameter of the wrapper `Connection`. The support for the "platform" parameter of the wrapper `Connection` has been removed. diff --git a/src/DriverManager.php b/src/DriverManager.php index bcb72b1c695..e929b582408 100644 --- a/src/DriverManager.php +++ b/src/DriverManager.php @@ -14,7 +14,6 @@ use Doctrine\DBAL\Exception\InvalidDriverClass; use Doctrine\DBAL\Exception\InvalidWrapperClass; use Doctrine\DBAL\Exception\UnknownDriver; -use Doctrine\Deprecations\Deprecation; use function array_keys; use function array_merge; @@ -94,25 +93,6 @@ final class DriverManager 'sqlsrv' => SQLSrv\Driver::class, ]; - /** - * List of URL schemes from a database URL and their mappings to driver. - * - * @deprecated Use actual driver names instead. - * - * @var string[] - */ - private static array $driverSchemeAliases = [ - 'db2' => 'ibm_db2', - 'mssql' => 'pdo_sqlsrv', - 'mysql' => 'pdo_mysql', - 'mysql2' => 'pdo_mysql', // Amazon RDS, for some weird reason - 'postgres' => 'pdo_pgsql', - 'postgresql' => 'pdo_pgsql', - 'pgsql' => 'pdo_pgsql', - 'sqlite' => 'pdo_sqlite', - 'sqlite3' => 'pdo_sqlite', - ]; - /** * Private constructor. This class cannot be instantiated. * @@ -298,8 +278,8 @@ private static function parseDatabaseUrl(array $params): array return $params; } - // (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid - $url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $params['url']); + // Patch the URL without a host to make it valid before parsing + $url = preg_replace('#^pdo-sqlite:///#', 'pdo-sqlite://localhost/', $params['url']); $url = parse_url($url); if ($url === false) { @@ -455,27 +435,7 @@ private static function parseDatabaseUrlScheme(?string $scheme, array $params): unset($params['driverClass']); // URL schemes must not contain underscores, but dashes are ok - $driver = str_replace('-', '_', $scheme); - - // If the driver is an alias (e.g. "postgres"), map it to the actual name ("pdo-pgsql"). - // Otherwise, let checkParams decide later if the driver exists. - if (isset(self::$driverSchemeAliases[$driver])) { - $actualDriver = self::$driverSchemeAliases[$driver]; - - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/5697', - 'Relying on driver name aliases is deprecated. Use %s instead of %s.', - str_replace('_', '-', $actualDriver), - $driver, - ); - - $driver = $actualDriver; - } - - // The requested driver from the URL scheme takes precedence over the - // default driver from the connection parameters. - $params['driver'] = $driver; + $params['driver'] = str_replace('-', '_', $scheme); return $params; } diff --git a/src/Exception/InvalidDriverClass.php b/src/Exception/InvalidDriverClass.php index 1c40d790e75..7ad23abdfe8 100644 --- a/src/Exception/InvalidDriverClass.php +++ b/src/Exception/InvalidDriverClass.php @@ -16,7 +16,7 @@ public static function new(string $driverClass): self { return new self( sprintf( - 'The given "driverClass" %s has to implement the %s interface.', + 'The given driver class %s has to implement the %s interface.', $driverClass, Driver::class, ), diff --git a/src/Exception/InvalidWrapperClass.php b/src/Exception/InvalidWrapperClass.php index b5e26626199..639e504eb49 100644 --- a/src/Exception/InvalidWrapperClass.php +++ b/src/Exception/InvalidWrapperClass.php @@ -16,7 +16,7 @@ public static function new(string $wrapperClass): self { return new self( sprintf( - 'The given "wrapperClass" %s has to be a subtype of %s.', + 'The given wrapper class %s has to be a subtype of %s.', $wrapperClass, Connection::class, ), diff --git a/src/Exception/UnknownDriver.php b/src/Exception/UnknownDriver.php index ba03cbd718b..917a0ffb8cf 100644 --- a/src/Exception/UnknownDriver.php +++ b/src/Exception/UnknownDriver.php @@ -17,7 +17,7 @@ public static function new(string $unknownDriverName, array $knownDrivers): self { return new self( sprintf( - 'The given "driver" "%s" is unknown, Doctrine currently supports only the following drivers: %s', + 'The given driver "%s" is unknown, Doctrine currently supports only the following drivers: %s', $unknownDriverName, implode(', ', $knownDrivers), ), diff --git a/tests/DriverManagerTest.php b/tests/DriverManagerTest.php index 4fe99ef6bba..0a29e5da6bd 100644 --- a/tests/DriverManagerTest.php +++ b/tests/DriverManagerTest.php @@ -43,7 +43,7 @@ public function testCustomWrapper(): void $wrapperClass = $wrapper::class; $options = [ - 'url' => 'sqlite::memory:', + 'url' => 'pdo-sqlite::memory:', 'wrapperClass' => $wrapperClass, ]; @@ -163,7 +163,7 @@ public function databaseUrls(): iterable return [ 'simple URL' => [ - 'mysql://foo:bar@localhost/baz', + 'pdo-mysql://foo:bar@localhost/baz', [ 'user' => 'foo', 'password' => 'bar', @@ -173,7 +173,7 @@ public function databaseUrls(): iterable ], ], 'simple URL with port' => [ - 'mysql://foo:bar@localhost:11211/baz', + 'pdo-mysql://foo:bar@localhost:11211/baz', [ 'user' => 'foo', 'password' => 'bar', @@ -184,42 +184,42 @@ public function databaseUrls(): iterable ], ], 'sqlite relative URL with host' => [ - 'sqlite://localhost/foo/dbname.sqlite', + 'pdo-sqlite://localhost/foo/dbname.sqlite', [ 'path' => 'foo/dbname.sqlite', 'driver' => PDO\SQLite\Driver::class, ], ], 'sqlite absolute URL with host' => [ - 'sqlite://localhost//tmp/dbname.sqlite', + 'pdo-sqlite://localhost//tmp/dbname.sqlite', [ 'path' => '/tmp/dbname.sqlite', 'driver' => PDO\SQLite\Driver::class, ], ], 'sqlite relative URL without host' => [ - 'sqlite:///foo/dbname.sqlite', + 'pdo-sqlite:///foo/dbname.sqlite', [ 'path' => 'foo/dbname.sqlite', 'driver' => PDO\SQLite\Driver::class, ], ], 'sqlite absolute URL without host' => [ - 'sqlite:////tmp/dbname.sqlite', + 'pdo-sqlite:////tmp/dbname.sqlite', [ 'path' => '/tmp/dbname.sqlite', 'driver' => PDO\SQLite\Driver::class, ], ], 'sqlite memory' => [ - 'sqlite:///:memory:', + 'pdo-sqlite:///:memory:', [ 'memory' => true, 'driver' => PDO\SQLite\Driver::class, ], ], 'sqlite memory with host' => [ - 'sqlite://localhost/:memory:', + 'pdo-sqlite://localhost/:memory:', [ 'memory' => true, 'driver' => PDO\SQLite\Driver::class, @@ -227,7 +227,7 @@ public function databaseUrls(): iterable ], 'params parsed from URL override individual params' => [ [ - 'url' => 'mysql://foo:bar@localhost/baz', + 'url' => 'pdo-mysql://foo:bar@localhost/baz', 'password' => 'lulz', ], [ @@ -240,7 +240,7 @@ public function databaseUrls(): iterable ], 'params not parsed from URL but individual params are preserved' => [ [ - 'url' => 'mysql://foo:bar@localhost/baz', + 'url' => 'pdo-mysql://foo:bar@localhost/baz', 'port' => 1234, ], [ @@ -253,7 +253,7 @@ public function databaseUrls(): iterable ], ], 'query params from URL are used as extra params' => [ - 'mysql://foo:bar@localhost/dbname?charset=UTF-8', + 'pdo-mysql://foo:bar@localhost/dbname?charset=UTF-8', ['charset' => 'UTF-8'], ], 'simple URL with fallthrough scheme not defined in map' => [ @@ -281,7 +281,7 @@ public function databaseUrls(): iterable ], ], 'simple URL with percent encoding' => [ - 'mysql://foo%3A:bar%2F@localhost/baz+baz%40', + 'pdo-mysql://foo%3A:bar%2F@localhost/baz+baz%40', [ 'user' => 'foo:', 'password' => 'bar/', @@ -291,7 +291,7 @@ public function databaseUrls(): iterable ], ], 'simple URL with percent sign in password' => [ - 'mysql://foo:bar%25bar@localhost/baz', + 'pdo-mysql://foo:bar%25bar@localhost/baz', [ 'user' => 'foo', 'password' => 'bar%bar', @@ -348,7 +348,7 @@ public function databaseUrls(): iterable ], 'URL with default driver' => [ [ - 'url' => 'mysql://foo:bar@localhost/baz', + 'url' => 'pdo-mysql://foo:bar@localhost/baz', 'driver' => 'sqlite', ], [ @@ -361,7 +361,7 @@ public function databaseUrls(): iterable ], 'URL with default custom driver' => [ [ - 'url' => 'mysql://foo:bar@localhost/baz', + 'url' => 'pdo-mysql://foo:bar@localhost/baz', 'driverClass' => $driverClass, ], [ @@ -374,7 +374,7 @@ public function databaseUrls(): iterable ], 'URL with default driver and default custom driver' => [ [ - 'url' => 'mysql://foo:bar@localhost/baz', + 'url' => 'pdo-mysql://foo:bar@localhost/baz', 'driver' => 'sqlite', 'driverClass' => $driverClass, ],