From 9a6e4bef0090214bca9025d11b8abc8b5de7dc19 Mon Sep 17 00:00:00 2001 From: Tomas Date: Fri, 5 Jan 2024 14:38:03 +0100 Subject: [PATCH] ORM3 and DBAL4 support --- .github/workflows/ci.yml | 24 +++------------ composer.json | 30 +++++++++---------- .../Types/AbstractEnumSQLDeclarationType.php | 13 ++------ .../Doctrine/DBAL/Types/AbstractEnumType.php | 14 ++------- .../DBAL/Types/AbstractFlagBagType.php | 13 ++++---- 5 files changed, 29 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 833574c..d6a4ade 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,38 +78,22 @@ jobs: # … # Most recent versions - - name: 'Test Symfony 5.4 [Linux, PHP 8.1]' + - name: 'Test Symfony 6.4 [Linux, PHP 8.1]' os: 'ubuntu-latest' php: '8.1' - symfony: '5.4.*@dev' + symfony: '6.4.*@dev' allow-unstable: true mongodb: true mysql: true - - name: 'Test Symfony 5.4 [Windows, PHP 8.1]' + - name: 'Test Symfony 6.4 [Windows, PHP 8.1]' os: 'windows-latest' php: '8.1' - symfony: '5.4.*@dev' - mongodb: true - mysql: true - allow-unstable: true - - - name: 'Test Symfony 6.3 [Linux, PHP 8.1]' - os: 'ubuntu-latest' - php: '8.1' - symfony: '6.3.*@dev' + symfony: '6.4.*@dev' mongodb: true mysql: true allow-unstable: true - - name: 'Test Symfony 6.4 [Linux, PHP 8.1]' - os: 'ubuntu-latest' - php: '8.1' - symfony: '6.4.*@dev' - allow-unstable: true - mysql: true - mongodb: true - - name: 'Test Symfony 7.0 [Linux, PHP 8.2]' os: 'ubuntu-latest' php: '8.2' diff --git a/composer.json b/composer.json index 580450f..b693e7b 100644 --- a/composer.json +++ b/composer.json @@ -41,22 +41,22 @@ "require-dev": { "ext-pdo_sqlite": "*", "composer/semver": "^3.2", - "doctrine/dbal": "^3.2", - "doctrine/doctrine-bundle": "^2.5", - "doctrine/orm": "^2.10", + "doctrine/dbal": "^4.0", + "doctrine/doctrine-bundle": "^2.11", + "doctrine/orm": "^3.0", "phpstan/phpstan": "^1.10", - "phpstan/phpstan-symfony": "^1.2", - "symfony/browser-kit": "^5.4|^6.3|^7.0", - "symfony/config": "^5.4|^6.3|^7.0", - "symfony/dependency-injection": "^5.4.2|^6.3|^7.0", - "symfony/filesystem": "^5.4|^6.3|^7.0", - "symfony/form": "^5.4|^6.3|^7.0", - "symfony/framework-bundle": "^5.4|^6.3|^7.0", - "symfony/http-kernel": "^5.4.2|^6.3|^7.0", - "symfony/phpunit-bridge": "^5.4|^6.3|^7.0", - "symfony/translation": "^5.4|^6.3|^7.0", - "symfony/var-dumper": "^5.4|^6.3|^7.0", - "symfony/yaml": "^5.4|^6.3|^7.0" + "phpstan/phpstan-symfony": "^1.3", + "symfony/browser-kit": "^6.4|^7.0", + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/filesystem": "^6.4|^7.0", + "symfony/form": "^6.4|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/phpunit-bridge": "^6.4|^7.0", + "symfony/translation": "^6.4|^7.0", + "symfony/var-dumper": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0" }, "extra": { "branch-alias": { diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php index 89b80a2..e4a29aa 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php @@ -12,7 +12,6 @@ namespace Elao\Enum\Bridge\Doctrine\DBAL\Types; -use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MySQLPlatform; use Elao\Enum\Exception\LogicException; @@ -25,16 +24,10 @@ abstract class AbstractEnumSQLDeclarationType extends AbstractEnumType /** * {@inheritdoc} */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string + public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { - if (class_exists(AbstractMySQLPlatform::class)) { - if (!$platform instanceof AbstractMySQLPlatform) { - throw new LogicException('SQL ENUM type is not supported on the current platform'); - } - } elseif (class_exists(MySQLPlatform::class)) { - if (!$platform instanceof MySQLPlatform) { - throw new LogicException('SQL ENUM type is not supported on the current platform'); - } + if (!$platform instanceof MySQLPlatform) { + throw new LogicException('SQL ENUM type is not supported on the current platform'); } $values = array_map( diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php index 533f22c..cd93562 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php @@ -103,23 +103,13 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st $column['length'] = 255; } - return method_exists($platform, 'getStringTypeDeclarationSQL') ? - $platform->getStringTypeDeclarationSQL($column) : - $platform->getVarcharTypeDeclarationSQL($column); + return $platform->getStringTypeDeclarationSQL($column); } /** * {@inheritdoc} */ - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } - - /** - * {@inheritdoc} - */ - public function getBindingType(): int + public function getBindingType(): ParameterType { return $this->isIntBackedEnum() ? ParameterType::INTEGER : ParameterType::STRING; } diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractFlagBagType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractFlagBagType.php index 760d744..e57dd7a 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractFlagBagType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractFlagBagType.php @@ -13,11 +13,11 @@ namespace Elao\Enum\Bridge\Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\IntegerType; +use Doctrine\DBAL\Types\Type; use Elao\Enum\Exception\InvalidArgumentException; use Elao\Enum\FlagBag; -abstract class AbstractFlagBagType extends IntegerType +abstract class AbstractFlagBagType extends Type { /** * The enum FQCN for which we should make the DBAL conversion. @@ -73,7 +73,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int * * @return FlagBag<\BackedEnum>|null */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform): ?FlagBag { $value = parent::convertToPHPValue($value, $platform); @@ -84,12 +84,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return new FlagBag($this->getEnumClass(), $value); } - /** - * {@inheritdoc} - */ - public function requiresSQLCommentHint(AbstractPlatform $platform): bool + public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { - return true; + return $platform->getIntegerTypeDeclarationSQL($column); } public function getName(): string