@@ -49,88 +49,88 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class DbalException extends Exception { |
| 51 | 51 | |
| 52 | - /** @var \Doctrine\DBAL\Exception */ |
|
| 53 | - private $original; |
|
| 52 | + /** @var \Doctrine\DBAL\Exception */ |
|
| 53 | + private $original; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param \Doctrine\DBAL\Exception $original |
|
| 57 | - * @param int $code |
|
| 58 | - * @param string $message |
|
| 59 | - */ |
|
| 60 | - private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) { |
|
| 61 | - parent::__construct( |
|
| 62 | - $message, |
|
| 63 | - $code, |
|
| 64 | - $original |
|
| 65 | - ); |
|
| 66 | - $this->original = $original; |
|
| 67 | - } |
|
| 55 | + /** |
|
| 56 | + * @param \Doctrine\DBAL\Exception $original |
|
| 57 | + * @param int $code |
|
| 58 | + * @param string $message |
|
| 59 | + */ |
|
| 60 | + private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) { |
|
| 61 | + parent::__construct( |
|
| 62 | + $message, |
|
| 63 | + $code, |
|
| 64 | + $original |
|
| 65 | + ); |
|
| 66 | + $this->original = $original; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self { |
|
| 70 | - return new self( |
|
| 71 | - $original, |
|
| 72 | - is_int($original->getCode()) ? $original->getCode() : 0, |
|
| 73 | - empty($message) ? $original->getMessage() : $message |
|
| 74 | - ); |
|
| 75 | - } |
|
| 69 | + public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self { |
|
| 70 | + return new self( |
|
| 71 | + $original, |
|
| 72 | + is_int($original->getCode()) ? $original->getCode() : 0, |
|
| 73 | + empty($message) ? $original->getMessage() : $message |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function getReason(): ?int { |
|
| 78 | - /** |
|
| 79 | - * Constraint errors |
|
| 80 | - */ |
|
| 81 | - if ($this->original instanceof ForeignKeyConstraintViolationException) { |
|
| 82 | - return parent::REASON_FOREIGN_KEY_VIOLATION; |
|
| 83 | - } |
|
| 84 | - if ($this->original instanceof NotNullConstraintViolationException) { |
|
| 85 | - return parent::REASON_NOT_NULL_CONSTRAINT_VIOLATION; |
|
| 86 | - } |
|
| 87 | - if ($this->original instanceof UniqueConstraintViolationException) { |
|
| 88 | - return parent::REASON_UNIQUE_CONSTRAINT_VIOLATION; |
|
| 89 | - } |
|
| 90 | - // The base exception comes last |
|
| 91 | - if ($this->original instanceof ConstraintViolationException) { |
|
| 92 | - return parent::REASON_CONSTRAINT_VIOLATION; |
|
| 93 | - } |
|
| 77 | + public function getReason(): ?int { |
|
| 78 | + /** |
|
| 79 | + * Constraint errors |
|
| 80 | + */ |
|
| 81 | + if ($this->original instanceof ForeignKeyConstraintViolationException) { |
|
| 82 | + return parent::REASON_FOREIGN_KEY_VIOLATION; |
|
| 83 | + } |
|
| 84 | + if ($this->original instanceof NotNullConstraintViolationException) { |
|
| 85 | + return parent::REASON_NOT_NULL_CONSTRAINT_VIOLATION; |
|
| 86 | + } |
|
| 87 | + if ($this->original instanceof UniqueConstraintViolationException) { |
|
| 88 | + return parent::REASON_UNIQUE_CONSTRAINT_VIOLATION; |
|
| 89 | + } |
|
| 90 | + // The base exception comes last |
|
| 91 | + if ($this->original instanceof ConstraintViolationException) { |
|
| 92 | + return parent::REASON_CONSTRAINT_VIOLATION; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Other server errors |
|
| 97 | - */ |
|
| 98 | - if ($this->original instanceof DatabaseObjectExistsException) { |
|
| 99 | - return parent::REASON_DATABASE_OBJECT_EXISTS; |
|
| 100 | - } |
|
| 101 | - if ($this->original instanceof DatabaseObjectNotFoundException) { |
|
| 102 | - return parent::REASON_DATABASE_OBJECT_NOT_FOUND; |
|
| 103 | - } |
|
| 104 | - if ($this->original instanceof DeadlockException) { |
|
| 105 | - return parent::REASON_DEADLOCK; |
|
| 106 | - } |
|
| 107 | - if ($this->original instanceof InvalidFieldNameException) { |
|
| 108 | - return parent::REASON_INVALID_FIELD_NAME; |
|
| 109 | - } |
|
| 110 | - if ($this->original instanceof NonUniqueFieldNameException) { |
|
| 111 | - return parent::REASON_NON_UNIQUE_FIELD_NAME; |
|
| 112 | - } |
|
| 113 | - if ($this->original instanceof SyntaxErrorException) { |
|
| 114 | - return parent::REASON_SYNTAX_ERROR; |
|
| 115 | - } |
|
| 116 | - // The base server exception class comes last |
|
| 117 | - if ($this->original instanceof ServerException) { |
|
| 118 | - return parent::REASON_SERVER; |
|
| 119 | - } |
|
| 95 | + /** |
|
| 96 | + * Other server errors |
|
| 97 | + */ |
|
| 98 | + if ($this->original instanceof DatabaseObjectExistsException) { |
|
| 99 | + return parent::REASON_DATABASE_OBJECT_EXISTS; |
|
| 100 | + } |
|
| 101 | + if ($this->original instanceof DatabaseObjectNotFoundException) { |
|
| 102 | + return parent::REASON_DATABASE_OBJECT_NOT_FOUND; |
|
| 103 | + } |
|
| 104 | + if ($this->original instanceof DeadlockException) { |
|
| 105 | + return parent::REASON_DEADLOCK; |
|
| 106 | + } |
|
| 107 | + if ($this->original instanceof InvalidFieldNameException) { |
|
| 108 | + return parent::REASON_INVALID_FIELD_NAME; |
|
| 109 | + } |
|
| 110 | + if ($this->original instanceof NonUniqueFieldNameException) { |
|
| 111 | + return parent::REASON_NON_UNIQUE_FIELD_NAME; |
|
| 112 | + } |
|
| 113 | + if ($this->original instanceof SyntaxErrorException) { |
|
| 114 | + return parent::REASON_SYNTAX_ERROR; |
|
| 115 | + } |
|
| 116 | + // The base server exception class comes last |
|
| 117 | + if ($this->original instanceof ServerException) { |
|
| 118 | + return parent::REASON_SERVER; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Generic errors |
|
| 123 | - */ |
|
| 124 | - if ($this->original instanceof ConnectionException) { |
|
| 125 | - return parent::REASON_CONNECTION_LOST; |
|
| 126 | - } |
|
| 127 | - if ($this->original instanceof InvalidArgumentException) { |
|
| 128 | - return parent::REASON_INVALID_ARGUMENT; |
|
| 129 | - } |
|
| 130 | - if ($this->original instanceof DriverException) { |
|
| 131 | - return parent::REASON_DRIVER; |
|
| 132 | - } |
|
| 121 | + /** |
|
| 122 | + * Generic errors |
|
| 123 | + */ |
|
| 124 | + if ($this->original instanceof ConnectionException) { |
|
| 125 | + return parent::REASON_CONNECTION_LOST; |
|
| 126 | + } |
|
| 127 | + if ($this->original instanceof InvalidArgumentException) { |
|
| 128 | + return parent::REASON_INVALID_ARGUMENT; |
|
| 129 | + } |
|
| 130 | + if ($this->original instanceof DriverException) { |
|
| 131 | + return parent::REASON_DRIVER; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - return null; |
|
| 135 | - } |
|
| 134 | + return null; |
|
| 135 | + } |
|
| 136 | 136 | } |