From 57fcde6fdbbedc7d3bddc53eacb3a4702263e43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 3 Feb 2024 16:37:06 +0100 Subject: [PATCH] Allow DBAL 4.0.x and make composer bootstrap passing --- bootstrap-types.php | 5 ++++- composer.json | 4 ++-- phpstan.neon.dist | 10 +++++----- src/Persistence/GenericPlatform.php | 4 +++- src/Persistence/Sql/Connection.php | 5 +++++ src/Type/LocalObjectType.php | 8 ++++++-- src/Type/MoneyType.php | 8 ++++++-- tests/ReferenceSqlTest.php | 3 +-- 8 files changed, 32 insertions(+), 15 deletions(-) diff --git a/bootstrap-types.php b/bootstrap-types.php index bc8a76a87..9dda68b5c 100644 --- a/bootstrap-types.php +++ b/bootstrap-types.php @@ -12,7 +12,10 @@ // force Doctrine\DBAL\Platforms\SQLitePlatform class load as in DBAL 3.x it is named with a different case // remove once DBAL 3.x support is dropped -new SqlitePlatform(); +try { + new SqlitePlatform(); +} catch (\Error $e) { +} DbalTypes\Type::addType(Types::LOCAL_OBJECT, LocalObjectType::class); DbalTypes\Type::addType(Types::MONEY, MoneyType::class); diff --git a/composer.json b/composer.json index d29401633..0f011dada 100644 --- a/composer.json +++ b/composer.json @@ -35,13 +35,13 @@ "require": { "php": ">=7.4 <8.4", "atk4/core": "dev-develop", - "doctrine/dbal": "~3.5.1 || ~3.6.0", + "doctrine/dbal": "~3.5.1 || ~3.6.0 || ~4.0.0", "mvorisek/atk4-hintable": "~1.9.0" }, "require-release": { "php": ">=7.4 <8.4", "atk4/core": "~5.1.0", - "doctrine/dbal": "~3.5.1 || ~3.6.0", + "doctrine/dbal": "~3.5.1 || ~3.6.0 || ~4.0.0", "mvorisek/atk4-hintable": "~1.9.0" }, "require-dev": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 55b2ec1a3..4e5263b31 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -38,11 +38,11 @@ parameters: path: '*' count: 3 - # FC for DBAL 4.0, remove once DBAL 3.x support is dropped - - - message: '~^Class Doctrine\\DBAL\\Platforms\\SqlitePlatform referenced with incorrect case: Doctrine\\DBAL\\Platforms\\SQLitePlatform\.$~' - path: '*' - count: 25 + # remove once DBAL 3.x support is dropped + - + message: '~^(Class Doctrine\\DBAL\\Platforms\\SQLitePlatform referenced with incorrect case: Doctrine\\DBAL\\Platforms\\SqlitePlatform\.|Dead catch - Error is never thrown in the try block\.)$~' + path: 'bootstrap-types.php' + count: 3 # TODO these rules are generated, this ignores should be fixed in the code # for src/Schema/TestCase.php diff --git a/src/Persistence/GenericPlatform.php b/src/Persistence/GenericPlatform.php index f13fee6df..1155101ef 100644 --- a/src/Persistence/GenericPlatform.php +++ b/src/Persistence/GenericPlatform.php @@ -14,7 +14,9 @@ private function createNotSupportedException(): \Exception return DbalException::notSupported('SQL'); } - #[\Override] + /** + * @deprecated remove once DBAL 3.x support is dropped + */ public function getName(): string { return 'atk4_data_generic'; diff --git a/src/Persistence/Sql/Connection.php b/src/Persistence/Sql/Connection.php index addea96e9..a9d4068ec 100644 --- a/src/Persistence/Sql/Connection.php +++ b/src/Persistence/Sql/Connection.php @@ -63,6 +63,11 @@ public function getConnection(): DbalConnection return $this->_connection; } + final public static function isDbal3x(): bool + { + return (new \ReflectionClass(AbstractPlatform::class))->hasMethod('getName'); + } + /** * Normalize DSN connection string or DBAL connection params described in: * https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html . diff --git a/src/Type/LocalObjectType.php b/src/Type/LocalObjectType.php index 9e2c7c8b9..4426f653c 100644 --- a/src/Type/LocalObjectType.php +++ b/src/Type/LocalObjectType.php @@ -41,7 +41,9 @@ protected function init(): void $this->handlesIndex = []; } - #[\Override] + /** + * @deprecated remove once DBAL 3.x support is dropped + */ public function getName(): string { return Types::LOCAL_OBJECT; @@ -112,7 +114,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?object return $res; } - #[\Override] + /** + * @deprecated remove once DBAL 3.x support is dropped + */ public function requiresSQLCommentHint(AbstractPlatform $platform): bool { return true; diff --git a/src/Type/MoneyType.php b/src/Type/MoneyType.php index 41db1cd2d..91e6f29f0 100644 --- a/src/Type/MoneyType.php +++ b/src/Type/MoneyType.php @@ -9,7 +9,9 @@ class MoneyType extends DbalTypes\Type { - #[\Override] + /** + * @deprecated remove once DBAL 3.x support is dropped + */ public function getName(): string { return Types::MONEY; @@ -37,7 +39,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?float return $this->convertToDatabaseValue($value, $platform); } - #[\Override] + /** + * @deprecated remove once DBAL 3.x support is dropped + */ public function requiresSQLCommentHint(AbstractPlatform $platform): bool { return true; diff --git a/tests/ReferenceSqlTest.php b/tests/ReferenceSqlTest.php index 9f9b5a5eb..725aba20d 100644 --- a/tests/ReferenceSqlTest.php +++ b/tests/ReferenceSqlTest.php @@ -308,9 +308,8 @@ public function testReferenceWithObjectId(): void $integerWrappedType = new class() extends DbalTypes\Type { /** - * TODO: Remove once DBAL 3.x support is dropped. + * @deprecated remove once DBAL 3.x support is dropped */ - #[\Override] public function getName(): string { return self::class;