Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove driver name aliases #5704

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
46 changes: 3 additions & 43 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidDriverClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidWrapperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnknownDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
34 changes: 17 additions & 17 deletions tests/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testCustomWrapper(): void
$wrapperClass = $wrapper::class;

$options = [
'url' => 'sqlite::memory:',
'url' => 'pdo-sqlite::memory:',
'wrapperClass' => $wrapperClass,
];

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -184,50 +184,50 @@ 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,
],
],
'params parsed from URL override individual params' => [
[
'url' => 'mysql://foo:bar@localhost/baz',
'url' => 'pdo-mysql://foo:bar@localhost/baz',
'password' => 'lulz',
],
[
Expand All @@ -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,
],
[
Expand All @@ -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' => [
Expand Down Expand Up @@ -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/',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
],
[
Expand All @@ -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,
],
[
Expand All @@ -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,
],
Expand Down