Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] feat: support doctrine/dbal 4 #306

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ jobs:
- php-version: 8.1
# add a specific job to test ^5.4 for all Symfony packages
symfony-version: "^5.4"
# `theofidry/alice-data-fixtures:1.6.0` and `doctrine/dbal:^4.0` cause issues:
# Error: Call to undefined method Doctrine\DBAL\Connection::exec()
composer-flags: "require doctrine/dbal:^3.0"
- php-version: 8.2
symfony-version: "^7.0"
- php-version: 8.3
symfony-version: "^7.0"

services:
mysql:
image: mysql:5.7
mariadb:
image: mariadb:11.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: acme
MARIADB_ROOT_PASSWORD: root
MARIADB_DATABASE: acme
ports:
- 3306:3306
postgresql:
image: postgres:9.6
image: postgres:15-alpine
env:
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'
Expand Down
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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.1'
services:
mariadb:
image: 'mariadb:11.0'
image: 'mariadb:11'
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=acme
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 named `SQLitePlatform`.
* On doctrine/dbal < 4.0, the class is named `SqlitePlatform`.
*/
private static function normalizeDriverName(string $driverName): string
{
if ('Doctrine\DBAL\Platforms\SqlitePlatform' === $driverName) {
return 'Doctrine\DBAL\Platforms\SQLitePlatform';
}

return $driverName;
}
}
1 change: 1 addition & 0 deletions tests/AppConfigMysql/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ doctrine:
dbname: acme
user: root
password: root
server_version: '11'
2 changes: 1 addition & 1 deletion tests/AppConfigMysqlUrl/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

doctrine:
dbal:
url: 'mysql://root:root@mariadb:3306/foobar'
url: 'mysql://root:root@mariadb:3306/foobar?serverVersion=11'
driver: pdo_mysql
1 change: 1 addition & 0 deletions tests/AppConfigPgsql/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ doctrine:
dbname: postgres
user: postgres
password: postgres
server_version: '15'