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

Deprecate classes in Driver\PDO* namespaces #4144

Merged
merged 1 commit into from
Jul 5, 2020
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
12 changes: 12 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Upgrade to 2.11

## PDO-related classes outside of the PDO namespace are deprecated

The following outside of the PDO namespace have been deprecated in favor of their counterparts in the PDO namespace:

- `PDOMySql\Driver` → `PDO\MySQL\Driver`
- `PDOOracle\Driver` → `PDO\OCI\Driver`
- `PDOPgSql\Driver` → `PDO\PgSQL\Driver`
- `PDOSqlite\Driver` → `PDO\SQLite\Driver`
- `PDOSqlsrv\Driver` → `PDO\SQLSrv\Driver`
- `PDOSqlsrv\Connection` → `PDO\SQLSrv\Connection`
- `PDOSqlsrv\Statement` → `PDO\SQLSrv\Statement`

## Deprecations in driver-level exception handling

1. The `ExceptionConverterDriver` interface and the usage of the `convertException()` method on the `Driver` objects are deprecated.
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/MySQL/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Doctrine\DBAL\Driver\PDO\MySQL;

use Doctrine\DBAL\Driver\PDOMySql;

final class Driver extends PDOMySql\Driver
{
}
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/OCI/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Doctrine\DBAL\Driver\PDO\OCI;

use Doctrine\DBAL\Driver\PDOOracle;

final class Driver extends PDOOracle\Driver
{
}
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/PgSQL/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Doctrine\DBAL\Driver\PDO\PgSQL;

use Doctrine\DBAL\Driver\PDOPgSql;

final class Driver extends PDOPgSql\Driver
{
}
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/SQLSrv/Connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Doctrine\DBAL\Driver\PDO\SQLSrv;

use Doctrine\DBAL\Driver\PDOSqlsrv;

final class Connection extends PDOSqlsrv\Connection
{
}
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/SQLSrv/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Doctrine\DBAL\Driver\PDO\SQLSrv;

use Doctrine\DBAL\Driver\PDOSqlsrv;

final class Driver extends PDOSqlsrv\Driver
{
}
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/SQLSrv/Statement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Doctrine\DBAL\Driver\PDO\SQLSrv;

use Doctrine\DBAL\Driver\PDOSqlsrv;

final class Statement extends PDOSqlsrv\Statement
{
}
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/SQLite/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Doctrine\DBAL\Driver\PDO\SQLite;

use Doctrine\DBAL\Driver\PDOSqlite;

final class Driver extends PDOSqlite\Driver
{
}
6 changes: 4 additions & 2 deletions lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\Driver\PDO\Connection;
use Doctrine\DBAL\Driver\PDO;
use PDOException;

/**
* PDO MySql driver.
*
* @deprecated Use {@link PDO\MySQL\Driver} instead.
*/
class Driver extends AbstractMySQLDriver
{
Expand All @@ -18,7 +20,7 @@ class Driver extends AbstractMySQLDriver
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
try {
$conn = new Connection(
$conn = new PDO\Connection(
$this->constructPdoDsn($params),
$username,
$password,
Expand Down
6 changes: 4 additions & 2 deletions lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractOracleDriver;
use Doctrine\DBAL\Driver\PDO\Connection;
use Doctrine\DBAL\Driver\PDO;
use PDOException;

/**
Expand All @@ -14,6 +14,8 @@
* stuff. PDO Oracle is not maintained by Oracle or anyone in the PHP community,
* which leads us to the recommendation to use the "oci8" driver to connect
* to Oracle instead.
*
* @deprecated Use {@link PDO\OCI\Driver} instead.
*/
class Driver extends AbstractOracleDriver
{
Expand All @@ -23,7 +25,7 @@ class Driver extends AbstractOracleDriver
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
try {
return new Connection(
return new PDO\Connection(
$this->constructPdoDsn($params),
$username,
$password,
Expand Down
13 changes: 7 additions & 6 deletions lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
use Doctrine\DBAL\Driver\PDO\Connection;
use PDO;
use Doctrine\DBAL\Driver\PDO;
use PDOException;

use function defined;

/**
* Driver that connects through pdo_pgsql.
*
* @deprecated Use {@link PDO\PgSQL\Driver} instead.
*/
class Driver extends AbstractPostgreSQLDriver
{
Expand All @@ -21,7 +22,7 @@ class Driver extends AbstractPostgreSQLDriver
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
try {
$pdo = new Connection(
$pdo = new PDO\Connection(
$this->_constructPdoDsn($params),
$username,
$password,
Expand All @@ -30,11 +31,11 @@ public function connect(array $params, $username = null, $password = null, array

if (
defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')
&& (! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])
|| $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] === true
&& (! isset($driverOptions[\PDO::PGSQL_ATTR_DISABLE_PREPARES])
|| $driverOptions[\PDO::PGSQL_ATTR_DISABLE_PREPARES] === true
)
) {
$pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
$pdo->setAttribute(\PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
}

/* defining client_encoding via SET NAMES to avoid inconsistent DSN support
Expand Down
6 changes: 4 additions & 2 deletions lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
use Doctrine\DBAL\Driver\PDO\Connection;
use Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use PDOException;

use function array_merge;

/**
* The PDO Sqlite driver.
*
* @deprecated Use {@link PDO\SQLite\Driver} instead.
*/
class Driver extends AbstractSQLiteDriver
{
Expand All @@ -36,7 +38,7 @@ public function connect(array $params, $username = null, $password = null, array
}

try {
$pdo = new Connection(
$pdo = new PDO\Connection(
$this->_constructPdoDsn($params),
$username,
$password,
Expand Down
9 changes: 5 additions & 4 deletions lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace Doctrine\DBAL\Driver\PDOSqlsrv;

use Doctrine\DBAL\Driver\PDO\Connection as BaseConnection;
use Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\ParameterType;
use PDO;

use function is_string;
use function strpos;
use function substr;

/**
* Sqlsrv Connection implementation.
*
* @deprecated Use {@link PDO\SQLSrv\Connection} instead.
*/
class Connection extends BaseConnection
class Connection extends PDO\Connection
{
/**
* @internal The connection can be only instantiated by its driver.
Expand All @@ -24,7 +25,7 @@ class Connection extends BaseConnection
public function __construct($dsn, $user = null, $password = null, ?array $options = null)
{
parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
$this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [PDO\SQLSrv\Statement::class, []]);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost;
use Doctrine\DBAL\Driver\PDO;

use function is_int;
use function sprintf;

/**
* The PDO-based Sqlsrv driver.
*
* @deprecated Use {@link PDO\SQLSrv\Driver} instead.
*/
class Driver extends AbstractSQLServerDriver
{
Expand All @@ -28,7 +31,7 @@ public function connect(array $params, $username = null, $password = null, array
}
}

return new Connection(
return new PDO\SQLSrv\Connection(
$this->_constructPdoDsn($params, $dsnOptions),
$username,
$password,
Expand Down
9 changes: 5 additions & 4 deletions lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Doctrine\DBAL\Driver\PDOSqlsrv;

use Doctrine\DBAL\Driver\PDO\Statement as BaseStatement;
use Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\ParameterType;
use PDO;

/**
* PDO SQL Server Statement
*
* @deprecated Use {@link PDO\SQLSrv\Statement} instead.
*/
class Statement extends BaseStatement
class Statement extends PDO\Statement
{
/**
* {@inheritdoc}
Expand All @@ -20,7 +21,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
($type === ParameterType::LARGE_OBJECT || $type === ParameterType::BINARY)
&& $driverOptions === null
) {
$driverOptions = PDO::SQLSRV_ENCODING_BINARY;
$driverOptions = \PDO::SQLSRV_ENCODING_BINARY;
}

return parent::bindParam($column, $variable, $type, $length, $driverOptions);
Expand Down
47 changes: 21 additions & 26 deletions lib/Doctrine/DBAL/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
namespace Doctrine\DBAL;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySQLDriver;
use Doctrine\DBAL\Driver\IBMDB2\Driver as IBMDB2Driver;
use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver;
use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver;
use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOCIDriver;
use Doctrine\DBAL\Driver\PDOPgSql\Driver as PDOPgSQLDriver;
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSQLiteDriver;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver;
use Doctrine\DBAL\Driver\SQLAnywhere\Driver as SQLAnywhereDriver;
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;
use PDO;
use Doctrine\DBAL\Driver\DrizzlePDOMySql;
use Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\SQLSrv;

use function array_keys;
use function array_map;
Expand Down Expand Up @@ -45,17 +40,17 @@ final class DriverManager
* @var string[]
*/
private static $_driverMap = [
'pdo_mysql' => PDOMySQLDriver::class,
'pdo_sqlite' => PDOSQLiteDriver::class,
'pdo_pgsql' => PDOPgSQLDriver::class,
'pdo_oci' => PDOOCIDriver::class,
'oci8' => OCI8Driver::class,
'ibm_db2' => IBMDB2Driver::class,
'pdo_sqlsrv' => PDOSQLSrvDriver::class,
'mysqli' => MySQLiDriver::class,
'drizzle_pdo_mysql' => DrizzlePDOMySQLDriver::class,
'sqlanywhere' => SQLAnywhereDriver::class,
'sqlsrv' => SQLSrvDriver::class,
'pdo_mysql' => PDO\MySQL\Driver::class,
'pdo_sqlite' => PDO\SQLite\Driver::class,
'pdo_pgsql' => PDO\PgSQL\Driver::class,
'pdo_oci' => PDO\OCI\Driver::class,
'oci8' => OCI8\Driver::class,
'ibm_db2' => IBMDB2\Driver::class,
'pdo_sqlsrv' => PDO\SQLSrv\Driver::class,
'mysqli' => Mysqli\Driver::class,
'drizzle_pdo_mysql' => DrizzlePDOMySql\Driver::class,
'sqlanywhere' => SQLAnywhere\Driver::class,
'sqlsrv' => SQLSrv\Driver::class,
];

/**
Expand Down Expand Up @@ -177,13 +172,13 @@ public static function getConnection(
}

// check for existing pdo object
if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) {
throw DBALException::invalidPdoInstance();
}

if (isset($params['pdo'])) {
$params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
$params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME);
} else {
self::_checkParams($params);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function testGetPassword(): void

public function testGetDriver(): void
{
self::assertInstanceOf(\Doctrine\DBAL\Driver\PDOMySql\Driver::class, $this->connection->getDriver());
self::assertInstanceOf(Driver\PDO\MySQL\Driver::class, $this->connection->getDriver());
}

public function testGetEventManager(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Driver/PDOMySql/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Doctrine\Tests\DBAL\Driver\PDOMySql;

use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDOMySql\Driver;
use Doctrine\DBAL\Driver\PDO\MySQL\Driver;
use Doctrine\Tests\DBAL\Driver\AbstractMySQLDriverTest;

class DriverTest extends AbstractMySQLDriverTest
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Driver/PDOOracle/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Doctrine\Tests\DBAL\Driver\PDOOracle;

use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDOOracle\Driver;
use Doctrine\DBAL\Driver\PDO\OCI\Driver;
use Doctrine\Tests\DBAL\Driver\AbstractOracleDriverTest;

class DriverTest extends AbstractOracleDriverTest
Expand Down
Loading