Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL;
4
 
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Types\Type;
621 lars 7
use SensitiveParameter;
148 lars 8
 
9
use function get_class;
10
use function gettype;
11
use function implode;
12
use function is_object;
13
use function spl_object_hash;
14
use function sprintf;
15
 
16
/** @psalm-immutable */
17
class Exception extends \Exception
18
{
19
    public static function notSupported(string $method): self
20
    {
21
        return new self(sprintf("Operation '%s' is not supported by platform.", $method));
22
    }
23
 
24
    /** @param mixed $invalidPlatform */
25
    public static function invalidPlatformType($invalidPlatform): self
26
    {
27
        if (is_object($invalidPlatform)) {
28
            return new self(
29
                sprintf(
30
                    "Option 'platform' must be a subtype of '%s', instance of '%s' given",
31
                    AbstractPlatform::class,
32
                    get_class($invalidPlatform),
33
                ),
34
            );
35
        }
36
 
37
        return new self(
38
            sprintf(
39
                "Option 'platform' must be an object and subtype of '%s'. Got '%s'",
40
                AbstractPlatform::class,
41
                gettype($invalidPlatform),
42
            ),
43
        );
44
    }
45
 
46
    /**
47
     * Returns a new instance for an invalid specified platform version.
48
     *
49
     * @param string $version        The invalid platform version given.
50
     * @param string $expectedFormat The expected platform version format.
51
     */
52
    public static function invalidPlatformVersionSpecified(string $version, string $expectedFormat): self
53
    {
54
        return new self(
55
            sprintf(
56
                'Invalid platform version "%s" specified. ' .
57
                'The platform version has to be specified in the format: "%s".',
58
                $version,
59
                $expectedFormat,
60
            ),
61
        );
62
    }
63
 
64
    /** @param string|null $url The URL that was provided in the connection parameters (if any). */
621 lars 65
    public static function driverRequired(
66
        #[SensitiveParameter]
67
        ?string $url = null
68
    ): self {
148 lars 69
        if ($url !== null) {
70
            return new self(
71
                sprintf(
72
                    "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " .
73
                    'is given to DriverManager::getConnection(). Given URL: %s',
74
                    $url,
75
                ),
76
            );
77
        }
78
 
79
        return new self("The options 'driver' or 'driverClass' are mandatory if no PDO " .
80
            'instance is given to DriverManager::getConnection().');
81
    }
82
 
83
    /** @param string[] $knownDrivers */
84
    public static function unknownDriver(string $unknownDriverName, array $knownDrivers): self
85
    {
86
        return new self("The given 'driver' " . $unknownDriverName . ' is unknown, ' .
87
            'Doctrine currently supports only the following drivers: ' . implode(', ', $knownDrivers));
88
    }
89
 
90
    public static function invalidWrapperClass(string $wrapperClass): self
91
    {
92
        return new self("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' .
93
            'subtype of \Doctrine\DBAL\Connection.');
94
    }
95
 
96
    public static function invalidDriverClass(string $driverClass): self
97
    {
98
        return new self(
99
            "The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.',
100
        );
101
    }
102
 
103
    public static function noColumnsSpecifiedForTable(string $tableName): self
104
    {
105
        return new self('No columns specified for table ' . $tableName);
106
    }
107
 
108
    public static function typeExists(string $name): self
109
    {
110
        return new self('Type ' . $name . ' already exists.');
111
    }
112
 
113
    public static function unknownColumnType(string $name): self
114
    {
115
        return new self('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' .
116
            'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' .
117
            'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' .
118
            'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' .
119
            'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' .
120
            'Type#getMappedDatabaseTypes(). If the type name is empty you might ' .
121
            'have a problem with the cache or forgot some mapping information.');
122
    }
123
 
124
    public static function typeNotFound(string $name): self
125
    {
126
        return new self('Type to be overwritten ' . $name . ' does not exist.');
127
    }
128
 
129
    public static function typeNotRegistered(Type $type): self
130
    {
131
        return new self(
132
            sprintf('Type of the class %s@%s is not registered.', get_class($type), spl_object_hash($type)),
133
        );
134
    }
135
 
136
    public static function typeAlreadyRegistered(Type $type): self
137
    {
138
        return new self(
139
            sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type)),
140
        );
141
    }
142
}