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