|
5 | 5 | namespace Doctrine\DBAL\Types\Exception; |
6 | 6 |
|
7 | 7 | use Exception; |
8 | | -use Throwable; |
9 | 8 |
|
10 | 9 | use function sprintf; |
11 | 10 |
|
12 | 11 | final class UnknownColumnType extends Exception implements TypesException |
13 | 12 | { |
14 | | - private function __construct( |
15 | | - private string $requestedType, |
16 | | - ?string $context, |
17 | | - int $code = 0, |
18 | | - ?Throwable $throwable = null, |
19 | | - ) { |
20 | | - $message = sprintf( |
21 | | - 'Unknown column type "%s" requested%s. Any Doctrine type that you use has ' |
| 13 | + private string $requestedType; |
| 14 | + |
| 15 | + public function getRequestedType(): string |
| 16 | + { |
| 17 | + return $this->requestedType; |
| 18 | + } |
| 19 | + |
| 20 | + public static function new(string $name): self |
| 21 | + { |
| 22 | + $object = new self(sprintf( |
| 23 | + 'Unknown column type "%s" requested. Any Doctrine type that you use has ' |
22 | 24 | . 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' |
23 | 25 | . 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' |
24 | 26 | . 'introspection then you might have forgotten to register all database types for a Doctrine Type. ' |
25 | 27 | . 'Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' |
26 | 28 | . 'Type#getMappedDatabaseTypes(). If the type name is empty you might ' |
27 | 29 | . 'have a problem with the cache or forgot some mapping information.', |
28 | | - $this->requestedType, |
29 | | - $context !== null ? ' for ' . $context : '', |
30 | | - ); |
| 30 | + $name, |
| 31 | + )); |
31 | 32 |
|
32 | | - parent::__construct($message, $code, $throwable); |
33 | | - } |
| 33 | + $object->requestedType = $name; |
34 | 34 |
|
35 | | - public function getType(): string |
36 | | - { |
37 | | - return $this->requestedType; |
| 35 | + return $object; |
38 | 36 | } |
39 | 37 |
|
40 | | - public static function new(string $name): self |
| 38 | + public static function newWithContext(string $name, string $tableName): self |
41 | 39 | { |
42 | | - return new self($name, null); |
43 | | - } |
| 40 | + $object = new self(sprintf( |
| 41 | + 'Unknown column type "%s" requested for table "%s". Any Doctrine type that you use has ' |
| 42 | + . 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' |
| 43 | + . 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' |
| 44 | + . 'introspection then you might have forgotten to register all database types for a Doctrine Type. ' |
| 45 | + . 'Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' |
| 46 | + . 'Type#getMappedDatabaseTypes(). If the type name is empty you might ' |
| 47 | + . 'have a problem with the cache or forgot some mapping information.', |
| 48 | + $name, |
| 49 | + $tableName, |
| 50 | + )); |
44 | 51 |
|
45 | | - public static function withContext(string $name, string $context): self |
46 | | - { |
47 | | - return new self($name, $context); |
| 52 | + $object->requestedType = $name; |
| 53 | + |
| 54 | + return $object; |
48 | 55 | } |
49 | 56 | } |
0 commit comments