diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php b/vendor/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php new file mode 100644 index 0000000..cb3bc64 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php | |||
@@ -0,0 +1,35 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\Mysqli\Exception; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractException; | ||
8 | use mysqli; | ||
9 | use mysqli_sql_exception; | ||
10 | use ReflectionProperty; | ||
11 | |||
12 | use function assert; | ||
13 | |||
14 | /** | ||
15 | * @internal | ||
16 | * | ||
17 | * @psalm-immutable | ||
18 | */ | ||
19 | final class ConnectionFailed extends AbstractException | ||
20 | { | ||
21 | public static function new(mysqli $connection): self | ||
22 | { | ||
23 | $error = $connection->connect_error; | ||
24 | assert($error !== null); | ||
25 | |||
26 | return new self($error, 'HY000', $connection->connect_errno); | ||
27 | } | ||
28 | |||
29 | public static function upcast(mysqli_sql_exception $exception): self | ||
30 | { | ||
31 | $p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate'); | ||
32 | |||
33 | return new self($exception->getMessage(), $p->getValue($exception), $exception->getCode(), $exception); | ||
34 | } | ||
35 | } | ||