Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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 sprintf;
13
 
14
/**
15
 * @internal
16
 *
17
 * @psalm-immutable
18
 */
19
final class InvalidCharset extends AbstractException
20
{
21
    public static function fromCharset(mysqli $connection, string $charset): self
22
    {
23
        return new self(
24
            sprintf('Failed to set charset "%s": %s', $charset, $connection->error),
25
            $connection->sqlstate,
26
            $connection->errno,
27
        );
28
    }
29
 
30
    public static function upcast(mysqli_sql_exception $exception, string $charset): self
31
    {
32
        $p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
33
        $p->setAccessible(true);
34
 
35
        return new self(
36
            sprintf('Failed to set charset "%s": %s', $charset, $exception->getMessage()),
37
            $p->getValue($exception),
38
            (int) $exception->getCode(),
39
            $exception,
40
        );
41
    }
42
}