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\IBMDB2\Exception;
6
 
7
use Doctrine\DBAL\Driver\AbstractException;
8
 
9
use function preg_match;
10
 
11
/**
12
 * @internal
13
 *
14
 * @psalm-immutable
15
 */
16
final class Factory
17
{
18
    /**
19
     * @param callable(int): T $constructor
20
     *
21
     * @return T
22
     *
23
     * @template T of AbstractException
24
     */
25
    public static function create(string $message, callable $constructor): AbstractException
26
    {
27
        $code = 0;
28
 
29
        if (preg_match('/ SQL(\d+)N /', $message, $matches) === 1) {
30
            $code = -(int) $matches[1];
31
        }
32
 
33
        return $constructor($code);
34
    }
35
}