Exception.php 591 Bytes
Newer Older
1 2 3 4 5 6
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\PDO;

7 8
use Doctrine\DBAL\Driver\AbstractException;
use PDOException;
9 10 11 12 13 14

/**
 * @internal
 *
 * @psalm-immutable
 */
15
final class Exception extends AbstractException
16
{
17
    public static function new(PDOException $exception): self
18
    {
19 20 21 22 23 24 25 26
        if ($exception->errorInfo !== null) {
            [$sqlState, $code] = $exception->errorInfo;
        } else {
            $code     = $exception->getCode();
            $sqlState = null;
        }

        return new self($exception->getMessage(), $sqlState, $code, $exception);
27 28
    }
}