Skip to content

Commit 2aaa154

Browse files
alongoszViniTou
authored andcommitted
Added DbPlatformInterface::configure contract
Mainly used to configure EnableForeignKeys middleware for SQLite.
1 parent 11290f3 commit 2aaa154

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/lib/Database/DbPlatform/DbPlatformInterface.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
namespace Ibexa\DoctrineSchema\Database\DbPlatform;
1010

1111
use Doctrine\Common\EventManager;
12+
use Doctrine\DBAL\Configuration;
1213

14+
/**
15+
* @internal
16+
*/
1317
interface DbPlatformInterface
1418
{
1519
/**
16-
* Get name of the driver associated with Database Platform implementation.
20+
* Get the name of the driver associated with Database Platform implementation.
1721
*
1822
* Every Database Platform implementation should extend Doctrine AbstractPlatform
1923
* (or its implementation).
@@ -26,4 +30,9 @@ public function getDriverName(): string;
2630
* Add event subscribers predefined and required by an implementation.
2731
*/
2832
public function addEventSubscribers(EventManager $eventManager): void;
33+
34+
/**
35+
* Add platform-based configuration to DBAL.
36+
*/
37+
public function configure(Configuration $dbalConfiguration): void;
2938
}

src/lib/Database/DbPlatform/PostgreSqlDbPlatform.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
namespace Ibexa\DoctrineSchema\Database\DbPlatform;
1010

1111
use Doctrine\Common\EventManager;
12+
use Doctrine\DBAL\Configuration;
1213
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1314
use Doctrine\DBAL\Schema\Table;
1415
use InvalidArgumentException;
1516

16-
class PostgreSqlDbPlatform extends PostgreSQLPlatform implements DbPlatformInterface
17+
/**
18+
* @internal
19+
*/
20+
final class PostgreSqlDbPlatform extends PostgreSQLPlatform implements DbPlatformInterface
1721
{
1822
public function addEventSubscribers(EventManager $eventManager): void
1923
{
@@ -49,4 +53,9 @@ public function getDropTableSQL($table): string
4953

5054
return 'DROP TABLE IF EXISTS ' . $table . ' CASCADE';
5155
}
56+
57+
public function configure(Configuration $dbalConfiguration): void
58+
{
59+
// Nothing to do
60+
}
5261
}

src/lib/Database/DbPlatform/SqliteDbPlatform.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
namespace Ibexa\DoctrineSchema\Database\DbPlatform;
1010

1111
use Doctrine\Common\EventManager;
12+
use Doctrine\DBAL\Configuration;
13+
use Doctrine\DBAL\Driver\AbstractSQLiteDriver\Middleware\EnableForeignKeys;
1214
use Doctrine\DBAL\Platforms\SqlitePlatform;
1315
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
1416
use Doctrine\DBAL\Schema\Table;
1517

16-
class SqliteDbPlatform extends SqlitePlatform implements DbPlatformInterface
18+
/**
19+
* @internal
20+
*/
21+
final class SqliteDbPlatform extends SqlitePlatform implements DbPlatformInterface
1722
{
1823
public function addEventSubscribers(EventManager $eventManager): void
1924
{
@@ -71,4 +76,9 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
7176
{
7277
return '-- ';
7378
}
79+
80+
public function configure(Configuration $dbalConfiguration): void
81+
{
82+
$dbalConfiguration->setMiddlewares([new EnableForeignKeys()]);
83+
}
7484
}

0 commit comments

Comments
 (0)