Skip to content

Commit c7ae8c8

Browse files
JulianMaramotl
authored andcommitted
DBAL3: Improve exception handling
1 parent 8bf6a95 commit c7ae8c8

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/Crate/DBAL/Platforms/CratePlatform.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs;
2929
use Doctrine\DBAL\Event\SchemaCreateTableEventArgs;
3030
use Doctrine\DBAL\Events;
31-
use Doctrine\DBAL\Exception as DBALException;
3231
use Doctrine\DBAL\Platforms\AbstractPlatform;
3332
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
3433
use Doctrine\DBAL\Schema\Identifier;
@@ -76,7 +75,7 @@ public function getSubstringExpression($value, $from = 0, $length = null): strin
7675
*/
7776
public function getNowExpression()
7877
{
79-
throw DBALException::notSupported(__METHOD__);
78+
throw Exception::notSupported(__METHOD__);
8079
}
8180

8281
/**
@@ -92,7 +91,7 @@ public function getRegexpExpression(): string
9291
*/
9392
public function getDateDiffExpression($date1, $date2): string
9493
{
95-
throw DBALException::notSupported(__METHOD__);
94+
throw Exception::notSupported(__METHOD__);
9695
}
9796

9897
/**
@@ -175,7 +174,7 @@ public function prefersSequences()
175174
*/
176175
public function getListDatabasesSQL(): string
177176
{
178-
throw DBALException::notSupported(__METHOD__);
177+
throw Exception::notSupported(__METHOD__);
179178
}
180179

181180
/**
@@ -270,20 +269,20 @@ public function getAlterTableSQL(TableDiff $diff): array
270269
}
271270

272271
if (count($diff->removedColumns) > 0) {
273-
throw DBALException::notSupported("Alter Table: drop columns");
272+
throw Exception::notSupported("Alter Table: drop columns");
274273
}
275274
if (count($diff->changedColumns) > 0) {
276-
throw DBALException::notSupported("Alter Table: change column options");
275+
throw Exception::notSupported("Alter Table: change column options");
277276
}
278277
if (count($diff->renamedColumns) > 0) {
279-
throw DBALException::notSupported("Alter Table: rename columns");
278+
throw Exception::notSupported("Alter Table: rename columns");
280279
}
281280

282281
$tableSql = array();
283282

284283
if (!$this->onSchemaAlterTable($diff, $tableSql)) {
285284
if ($diff->newName !== false) {
286-
throw DBALException::notSupported("Alter Table: rename table");
285+
throw Exception::notSupported("Alter Table: rename table");
287286
}
288287

289288
$sql = array_merge($sql, $this->getPreAlterTableIndexForeignKeySQL($diff), $commentsSQL);
@@ -514,15 +513,15 @@ public function getTimeFormatString(): string
514513
*/
515514
public function getTruncateTableSQL($tableName, $cascade = false): string
516515
{
517-
throw DBALException::notSupported(__METHOD__);
516+
throw Exception::notSupported(__METHOD__);
518517
}
519518

520519
/**
521520
* {@inheritDoc}
522521
*/
523522
public function getReadLockSQL()
524523
{
525-
throw DBALException::notSupported(__METHOD__);
524+
throw Exception::notSupported(__METHOD__);
526525
}
527526

528527
/**
@@ -580,7 +579,7 @@ protected function getReservedKeywordsClass()
580579
*/
581580
public function getBlobTypeDeclarationSQL(array $field): string
582581
{
583-
throw DBALException::notSupported(__METHOD__);
582+
throw Exception::notSupported(__METHOD__);
584583
}
585584

586585
/**
@@ -620,7 +619,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE
620619
}, $index->getColumns());
621620
$options['primary_index'] = $index;
622621
} elseif ($index->isUnique()) {
623-
throw DBALException::notSupported(
622+
throw Exception::notSupported(
624623
"Unique constraints are not supported. Use `primary key` instead"
625624
);
626625
} else {
@@ -693,7 +692,7 @@ protected function _getCreateTableSQL($name, array $columns, array $options = ar
693692
}
694693

695694
if (isset($options['foreignKeys'])) {
696-
throw DBALException::notSupported("Create Table: foreign keys");
695+
throw Exception::notSupported("Create Table: foreign keys");
697696
}
698697

699698
$query = 'CREATE TABLE ' . $name . ' (' . $columnListSql . ')';
@@ -783,12 +782,12 @@ private function buildPartitionOptions(array $options)
783782
* @param array List of primary key column names
784783
*
785784
* @return array The column data as associative array.
786-
* @throws DBALException
785+
* @throws Exception
787786
*/
788787
public static function prepareColumnData(AbstractPlatform $platform, $column, $primaries = array())
789788
{
790789
if ($column->hasCustomSchemaOption("unique") ? $column->getCustomSchemaOption("unique") : false) {
791-
throw DBALException::notSupported("Unique constraints are not supported. Use `primary key` instead");
790+
throw Exception::notSupported("Unique constraints are not supported. Use `primary key` instead");
792791
}
793792

794793
$columnData = array();
@@ -826,31 +825,31 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p
826825
*/
827826
public function getCreateDatabaseSQL($database): string
828827
{
829-
throw DBALException::notSupported(__METHOD__);
828+
throw Exception::notSupported(__METHOD__);
830829
}
831830

832831
/**
833832
* {@inheritDoc}
834833
*/
835834
public function getDropDatabaseSQL($database): string
836835
{
837-
throw DBALException::notSupported(__METHOD__);
836+
throw Exception::notSupported(__METHOD__);
838837
}
839838

840839
/**
841840
* {@inheritDoc}
842841
*/
843842
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table): string
844843
{
845-
throw DBALException::notSupported(__METHOD__);
844+
throw Exception::notSupported(__METHOD__);
846845
}
847846

848847
/**
849848
* {@inheritDoc}
850849
*/
851850
public function getGuidTypeDeclarationSQL(array $field): string
852851
{
853-
throw DBALException::notSupported(__METHOD__);
852+
throw Exception::notSupported(__METHOD__);
854853
}
855854

856855
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Crate\DBAL\Platforms;
3+
use Doctrine\DBAL\Exception as DoctrineException;
4+
class Exception extends \Exception implements DoctrineException
5+
{
6+
public static function notSupported(string $method): self
7+
{
8+
return new self(sprintf("Operation '%s' is not supported by platform.", $method));
9+
}
10+
}
11+
12+
?>

0 commit comments

Comments
 (0)