Skip to content

Commit

Permalink
Revert "Undeprecate \Doctrine\DBAL\Driver\DriverException interface"
Browse files Browse the repository at this point in the history
This reverts commit 64ebece.
  • Loading branch information
beberlei committed Oct 17, 2020
1 parent 3ba2f43 commit 0b29130
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 103 deletions.
4 changes: 2 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The non-interface methods of driver-level classes have been marked internal:

The following classes under the `Driver` namespace have been deprecated in favor of their consistently named counterparts:

- `DriverException``Exception`
- `AbstractDriverException``AbstractException`
- `IBMDB2\DB2Driver``IBMDB2\Driver`
- `IBMDB2\DB2Connection``IBMDB2\Connection`
Expand All @@ -109,8 +110,7 @@ All driver-specific exception classes have been deprecated:
- `PDOException`
- `SQLSrv\SQLSrvException`

A driver-level exception should be only identified as a subtype of `Doctrine\DBAL\Driver\DriverException`
or when its wrapped as `Doctrine\DBAL\Exception\DriverException`.
A driver-level exception should be only identified as a subtype of `Driver\Exception`.
Internal driver-level exception implementations may use `Driver\AbstractException` as the base class.
Driver-specific exception handling has to be implemented either in the driver or based on the type of the `Driver` implementation.

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ArrayIterator;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\ResultStatement;
Expand Down Expand Up @@ -297,7 +297,7 @@ public function free(): void
/**
* @return array<string,mixed>|false
*
* @throws DriverException
* @throws Exception
*/
private function doFetch()
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Doctrine\DBAL;

use Doctrine\DBAL\Driver\DriverException as LowLevelDriverException;
use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
Expand Down Expand Up @@ -177,7 +177,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, strin
return $driverEx;
}

if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof LowLevelDriverException) {
if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DeprecatedDriverException) {
return $driver->convertException($msg, $driverEx);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function convertException($message, DeprecatedDriverException $exception)
return new TableExistsException($message, $exception);

case '08006':
return new ConnectionException($message, $exception);
return new Exception\ConnectionException($message, $exception);

case '7':
// Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.3.22 and PHP 7.4.10),
Expand Down
28 changes: 3 additions & 25 deletions lib/Doctrine/DBAL/Driver/DriverException.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver;

use Throwable;

/**
* @deprecated Use {@link Exception} instead
*
* @psalm-immutable
*/
interface DriverException extends Throwable
interface DriverException extends Exception
{
/**
* Returns the driver specific error code if available.
*
* @deprecated Use {@link getCode()} or {@link getSQLState()} instead
*
* Returns null if no driver specific error code is available
* for the error raised by the driver.
*
* @return int|string|null
*/
public function getErrorCode();

/**
* Returns the SQLSTATE the driver was in at the time the error occurred.
*
* Returns null if the driver does not provide a SQLSTATE for the error occurred.
*
* @return string|null
*/
public function getSQLState();
}
34 changes: 34 additions & 0 deletions lib/Doctrine/DBAL/Driver/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver;

use Throwable;

/**
* @psalm-immutable
*/
interface Exception extends Throwable
{
/**
* Returns the driver specific error code if available.
*
* @deprecated Use {@link getCode()} or {@link getSQLState()} instead
*
* Returns null if no driver specific error code is available
* for the error raised by the driver.
*
* @return int|string|null
*/
public function getErrorCode();

/**
* Returns the SQLSTATE the driver was in at the time the error occurred.
*
* Returns null if the driver does not provide a SQLSTATE for the error occurred.
*
* @return string|null
*/
public function getSQLState();
}
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Driver/FetchUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class FetchUtils
/**
* @return mixed|false
*
* @throws DriverException
* @throws Exception
*/
public static function fetchOne(Result $result)
{
Expand All @@ -28,7 +28,7 @@ public static function fetchOne(Result $result)
/**
* @return array<int,array<int,mixed>>
*
* @throws DriverException
* @throws Exception
*/
public static function fetchAllNumeric(Result $result): array
{
Expand All @@ -44,7 +44,7 @@ public static function fetchAllNumeric(Result $result): array
/**
* @return array<int,array<string,mixed>>
*
* @throws DriverException
* @throws Exception
*/
public static function fetchAllAssociative(Result $result): array
{
Expand All @@ -60,7 +60,7 @@ public static function fetchAllAssociative(Result $result): array
/**
* @return array<int,mixed>
*
* @throws DriverException
* @throws Exception
*/
public static function fetchFirstColumn(Result $result): array
{
Expand Down
20 changes: 20 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDO/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\PDO;

use Doctrine\DBAL\Driver\PDOException;

/**
* @internal
*
* @psalm-immutable
*/
final class Exception extends PDOException
{
public static function new(\PDOException $exception): self
{
return new self($exception);
}
}
23 changes: 12 additions & 11 deletions lib/Doctrine/DBAL/Driver/PDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Doctrine\DBAL\Driver;

use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Driver\PDO\Statement;
use PDO;
use PDOException as OriginalPDOException;
use PDOException;
use PDOStatement;

use function assert;
Expand Down Expand Up @@ -35,8 +36,8 @@ public function __construct($dsn, $user = null, $password = null, ?array $option
parent::__construct($dsn, (string) $user, (string) $password, (array) $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (OriginalPDOException $exception) {
throw PDOException::new($exception);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

Expand All @@ -50,8 +51,8 @@ public function exec($sql)
assert($result !== false);

return $result;
} catch (OriginalPDOException $exception) {
throw PDOException::new($exception);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

Expand All @@ -76,8 +77,8 @@ public function prepare($sql, $driverOptions = [])
assert($statement instanceof PDOStatement);

return $statement;
} catch (OriginalPDOException $exception) {
throw PDOException::new($exception);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

Expand All @@ -95,8 +96,8 @@ public function query()
assert($stmt instanceof PDOStatement);

return $stmt;
} catch (OriginalPDOException $exception) {
throw PDOException::new($exception);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

Expand All @@ -111,8 +112,8 @@ public function lastInsertId($name = null)
}

return parent::lastInsertId($name);
} catch (OriginalPDOException $exception) {
throw PDOException::new($exception);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

Expand Down
7 changes: 2 additions & 5 deletions lib/Doctrine/DBAL/Driver/PDOException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Doctrine\DBAL\Driver\PDO\Exception;

/**
* @deprecated Use {@link Exception} instead
*
* @psalm-immutable
*/
class PDOException extends \PDOException implements DriverException
Expand All @@ -23,11 +25,6 @@ class PDOException extends \PDOException implements DriverException
*/
private $sqlState;

public static function new(\PDOException $exception): self
{
return new self($exception);
}

/**
* @param \PDOException $exception The PDO exception to wrap.
*/
Expand Down
16 changes: 8 additions & 8 deletions lib/Doctrine/DBAL/Driver/PDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Doctrine\DBAL\Driver;

use Doctrine\DBAL\Driver\PDOException as DoctrinePDOException;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
Expand Down Expand Up @@ -77,7 +77,7 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)

return parent::setFetchMode($fetchMode, $arg2, $arg3);
} catch (PDOException $exception) {
throw DoctrinePDOException::new($exception);
throw Exception::new($exception);
}
}

Expand All @@ -91,7 +91,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
try {
return parent::bindValue($param, $value, $type);
} catch (PDOException $exception) {
throw DoctrinePDOException::new($exception);
throw Exception::new($exception);
}
}

Expand All @@ -111,7 +111,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
try {
return parent::bindParam($param, $variable, $type, ...array_slice(func_get_args(), 3));
} catch (PDOException $exception) {
throw DoctrinePDOException::new($exception);
throw Exception::new($exception);
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ public function execute($params = null)
try {
return parent::execute($params);
} catch (PDOException $exception) {
throw DoctrinePDOException::new($exception);
throw Exception::new($exception);
}
}

Expand All @@ -159,7 +159,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
try {
return parent::fetch(...$args);
} catch (PDOException $exception) {
throw DoctrinePDOException::new($exception);
throw Exception::new($exception);
}
}

Expand Down Expand Up @@ -192,7 +192,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n

return $data;
} catch (PDOException $exception) {
throw DoctrinePDOException::new($exception);
throw Exception::new($exception);
}
}

Expand All @@ -206,7 +206,7 @@ public function fetchColumn($columnIndex = 0)
try {
return parent::fetchColumn($columnIndex);
} catch (PDOException $exception) {
throw DoctrinePDOException::new($exception);
throw Exception::new($exception);
}
}

Expand Down
Loading

0 comments on commit 0b29130

Please sign in to comment.