Skip to content

Commit 0b29130

Browse files
committed
Revert "Undeprecate \Doctrine\DBAL\Driver\DriverException interface"
This reverts commit 64ebece.
1 parent 3ba2f43 commit 0b29130

23 files changed

+152
-103
lines changed

UPGRADE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The non-interface methods of driver-level classes have been marked internal:
8888

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

91+
- `DriverException``Exception`
9192
- `AbstractDriverException``AbstractException`
9293
- `IBMDB2\DB2Driver``IBMDB2\Driver`
9394
- `IBMDB2\DB2Connection``IBMDB2\Connection`
@@ -109,8 +110,7 @@ All driver-specific exception classes have been deprecated:
109110
- `PDOException`
110111
- `SQLSrv\SQLSrvException`
111112

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

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use ArrayIterator;
66
use Doctrine\Common\Cache\Cache;
7-
use Doctrine\DBAL\Driver\DriverException;
7+
use Doctrine\DBAL\Driver\Exception;
88
use Doctrine\DBAL\Driver\FetchUtils;
99
use Doctrine\DBAL\Driver\Result;
1010
use Doctrine\DBAL\Driver\ResultStatement;
@@ -297,7 +297,7 @@ public function free(): void
297297
/**
298298
* @return array<string,mixed>|false
299299
*
300-
* @throws DriverException
300+
* @throws Exception
301301
*/
302302
private function doFetch()
303303
{

lib/Doctrine/DBAL/DBALException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Doctrine\DBAL;
44

5-
use Doctrine\DBAL\Driver\DriverException as LowLevelDriverException;
5+
use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException;
66
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
77
use Doctrine\DBAL\Exception\DriverException;
88
use Doctrine\DBAL\Platforms\AbstractPlatform;
@@ -177,7 +177,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, strin
177177
return $driverEx;
178178
}
179179

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

lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function convertException($message, DeprecatedDriverException $exception)
8585
return new TableExistsException($message, $exception);
8686

8787
case '08006':
88-
return new ConnectionException($message, $exception);
88+
return new Exception\ConnectionException($message, $exception);
8989

9090
case '7':
9191
// Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.3.22 and PHP 7.4.10),
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Doctrine\DBAL\Driver;
64

7-
use Throwable;
8-
95
/**
6+
* @deprecated Use {@link Exception} instead
7+
*
108
* @psalm-immutable
119
*/
12-
interface DriverException extends Throwable
10+
interface DriverException extends Exception
1311
{
14-
/**
15-
* Returns the driver specific error code if available.
16-
*
17-
* @deprecated Use {@link getCode()} or {@link getSQLState()} instead
18-
*
19-
* Returns null if no driver specific error code is available
20-
* for the error raised by the driver.
21-
*
22-
* @return int|string|null
23-
*/
24-
public function getErrorCode();
25-
26-
/**
27-
* Returns the SQLSTATE the driver was in at the time the error occurred.
28-
*
29-
* Returns null if the driver does not provide a SQLSTATE for the error occurred.
30-
*
31-
* @return string|null
32-
*/
33-
public function getSQLState();
3412
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Driver;
6+
7+
use Throwable;
8+
9+
/**
10+
* @psalm-immutable
11+
*/
12+
interface Exception extends Throwable
13+
{
14+
/**
15+
* Returns the driver specific error code if available.
16+
*
17+
* @deprecated Use {@link getCode()} or {@link getSQLState()} instead
18+
*
19+
* Returns null if no driver specific error code is available
20+
* for the error raised by the driver.
21+
*
22+
* @return int|string|null
23+
*/
24+
public function getErrorCode();
25+
26+
/**
27+
* Returns the SQLSTATE the driver was in at the time the error occurred.
28+
*
29+
* Returns null if the driver does not provide a SQLSTATE for the error occurred.
30+
*
31+
* @return string|null
32+
*/
33+
public function getSQLState();
34+
}

lib/Doctrine/DBAL/Driver/FetchUtils.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class FetchUtils
1212
/**
1313
* @return mixed|false
1414
*
15-
* @throws DriverException
15+
* @throws Exception
1616
*/
1717
public static function fetchOne(Result $result)
1818
{
@@ -28,7 +28,7 @@ public static function fetchOne(Result $result)
2828
/**
2929
* @return array<int,array<int,mixed>>
3030
*
31-
* @throws DriverException
31+
* @throws Exception
3232
*/
3333
public static function fetchAllNumeric(Result $result): array
3434
{
@@ -44,7 +44,7 @@ public static function fetchAllNumeric(Result $result): array
4444
/**
4545
* @return array<int,array<string,mixed>>
4646
*
47-
* @throws DriverException
47+
* @throws Exception
4848
*/
4949
public static function fetchAllAssociative(Result $result): array
5050
{
@@ -60,7 +60,7 @@ public static function fetchAllAssociative(Result $result): array
6060
/**
6161
* @return array<int,mixed>
6262
*
63-
* @throws DriverException
63+
* @throws Exception
6464
*/
6565
public static function fetchFirstColumn(Result $result): array
6666
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Driver\PDO;
6+
7+
use Doctrine\DBAL\Driver\PDOException;
8+
9+
/**
10+
* @internal
11+
*
12+
* @psalm-immutable
13+
*/
14+
final class Exception extends PDOException
15+
{
16+
public static function new(\PDOException $exception): self
17+
{
18+
return new self($exception);
19+
}
20+
}

lib/Doctrine/DBAL/Driver/PDOConnection.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace Doctrine\DBAL\Driver;
44

55
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
6+
use Doctrine\DBAL\Driver\PDO\Exception;
67
use Doctrine\DBAL\Driver\PDO\Statement;
78
use PDO;
8-
use PDOException as OriginalPDOException;
9+
use PDOException;
910
use PDOStatement;
1011

1112
use function assert;
@@ -35,8 +36,8 @@ public function __construct($dsn, $user = null, $password = null, ?array $option
3536
parent::__construct($dsn, (string) $user, (string) $password, (array) $options);
3637
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
3738
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
38-
} catch (OriginalPDOException $exception) {
39-
throw PDOException::new($exception);
39+
} catch (PDOException $exception) {
40+
throw Exception::new($exception);
4041
}
4142
}
4243

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

5253
return $result;
53-
} catch (OriginalPDOException $exception) {
54-
throw PDOException::new($exception);
54+
} catch (PDOException $exception) {
55+
throw Exception::new($exception);
5556
}
5657
}
5758

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

7879
return $statement;
79-
} catch (OriginalPDOException $exception) {
80-
throw PDOException::new($exception);
80+
} catch (PDOException $exception) {
81+
throw Exception::new($exception);
8182
}
8283
}
8384

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

9798
return $stmt;
98-
} catch (OriginalPDOException $exception) {
99-
throw PDOException::new($exception);
99+
} catch (PDOException $exception) {
100+
throw Exception::new($exception);
100101
}
101102
}
102103

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

113114
return parent::lastInsertId($name);
114-
} catch (OriginalPDOException $exception) {
115-
throw PDOException::new($exception);
115+
} catch (PDOException $exception) {
116+
throw Exception::new($exception);
116117
}
117118
}
118119

lib/Doctrine/DBAL/Driver/PDOException.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Doctrine\DBAL\Driver\PDO\Exception;
66

77
/**
8+
* @deprecated Use {@link Exception} instead
9+
*
810
* @psalm-immutable
911
*/
1012
class PDOException extends \PDOException implements DriverException
@@ -23,11 +25,6 @@ class PDOException extends \PDOException implements DriverException
2325
*/
2426
private $sqlState;
2527

26-
public static function new(\PDOException $exception): self
27-
{
28-
return new self($exception);
29-
}
30-
3128
/**
3229
* @param \PDOException $exception The PDO exception to wrap.
3330
*/

0 commit comments

Comments
 (0)