Skip to content

Commit

Permalink
feat: support doctrine/dbal 4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed May 4, 2024
1 parent 17124fe commit 284b599
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"conflict": {
"doctrine/annotations": "<1.13.1 || >=3.0",
"doctrine/dbal": "<2.13.1 || ~3.0.0 || >=4.0",
"doctrine/dbal": "<2.13.1 || ~3.0.0 || >=5.0",
"doctrine/mongodb-odm": "<2.2 || >=3.0",
"doctrine/orm": "<2.14 || >=4.0"
},
Expand Down
19 changes: 18 additions & 1 deletion src/Services/DatabaseToolCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function __construct(ContainerInterface $container, mixed $annotationRead

public function add(AbstractDatabaseTool $databaseTool): void
{
$this->items[$databaseTool->getType()][$databaseTool->getDriverName()] = $databaseTool;
$driverName = self::normalizeDriverName($databaseTool->getDriverName());

$this->items[$databaseTool->getType()][$driverName] = $databaseTool;
}

public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode = null): AbstractDatabaseTool
Expand All @@ -49,6 +51,8 @@ public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode
$registry = $this->container->get($registryName);
$driverName = ('ORM' === $registry->getName()) ? \get_class($registry->getConnection()->getDatabasePlatform()) : 'default';

$driverName = self::normalizeDriverName($driverName);

$databaseTool = $this->items[$registry->getName()][$driverName] ?? $this->items[$registry->getName()]['default'];

$databaseTool->setRegistry($registry);
Expand All @@ -57,4 +61,17 @@ public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode

return $databaseTool;
}

/**
* On doctrine/dbal ^4.0, the class is SQLitePlatform.
* On doctrine/dbal < 4.0, the class is SqlitePlatform.
*/
private static function normalizeDriverName(string $driverName): string
{
if ('Doctrine\DBAL\Platforms\SqlitePlatform' === $driverName) {
return 'Doctrine\DBAL\Platforms\SQLitePlatform';
}

return $driverName;
}
}

0 comments on commit 284b599

Please sign in to comment.