From a830ecb0f7797ae5d754f4e81e1caee8fafc126b Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 24 Oct 2023 20:21:03 -0400 Subject: [PATCH 1/4] feat: Symfony 7 support --- .github/workflows/continuous-integration.yml | 4 +++ Form/DoctrineMongoDBExtension.php | 5 ++-- Form/DoctrineMongoDBTypeGuesser.php | 14 ++++----- Tests/Validator/Constraints/UniqueTest.php | 9 ++---- composer.json | 31 ++++++++++---------- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 130f5274..e9533536 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -30,6 +30,7 @@ jobs: symfony-version: - "5.4.*" - "6.4.*" + - "7.0.x" driver-version: - "stable" dependencies: @@ -41,6 +42,9 @@ jobs: driver-version: "1.5.0" stability: "stable" symfony-version: "5.4.*" + exclude: + - php-version: "8.1" + symfony-version: "7.0.x" services: mongodb: diff --git a/Form/DoctrineMongoDBExtension.php b/Form/DoctrineMongoDBExtension.php index 2cda9710..7428e77c 100644 --- a/Form/DoctrineMongoDBExtension.php +++ b/Form/DoctrineMongoDBExtension.php @@ -23,15 +23,14 @@ public function __construct(ManagerRegistry $registry) } /** @return FormTypeInterface[] */ - protected function loadTypes() + protected function loadTypes(): array { return [ new Type\DocumentType($this->registry), ]; } - /** @return FormTypeGuesserInterface|null */ - protected function loadTypeGuesser() + protected function loadTypeGuesser(): ?FormTypeGuesserInterface { return new DoctrineMongoDBTypeGuesser($this->registry); } diff --git a/Form/DoctrineMongoDBTypeGuesser.php b/Form/DoctrineMongoDBTypeGuesser.php index 4f69b16c..8330eec4 100644 --- a/Form/DoctrineMongoDBTypeGuesser.php +++ b/Form/DoctrineMongoDBTypeGuesser.php @@ -38,8 +38,7 @@ public function __construct(ManagerRegistry $registry) $this->registry = $registry; } - /** @return TypeGuess|null */ - public function guessType(string $class, string $property) + public function guessType(string $class, string $property): ?TypeGuess { $ret = $this->getMetadata($class); if (! $ret) { @@ -114,10 +113,11 @@ public function guessType(string $class, string $property) Guess::MEDIUM_CONFIDENCE, ); } + + return null; } - /** @return ValueGuess|null */ - public function guessRequired(string $class, string $property) + public function guessRequired(string $class, string $property): ?ValueGuess { $ret = $this->getMetadata($class); if ($ret && $ret[0]->hasField($property)) { @@ -137,8 +137,7 @@ public function guessRequired(string $class, string $property) return null; } - /** @return ValueGuess|null */ - public function guessMaxLength(string $class, string $property) + public function guessMaxLength(string $class, string $property): ?ValueGuess { return null; } @@ -150,8 +149,7 @@ public function guessMinLength($class, $property): void { } - /** @return ValueGuess|null */ - public function guessPattern(string $class, string $property) + public function guessPattern(string $class, string $property): ?ValueGuess { $ret = $this->getMetadata($class); if (! $ret || ! $ret[0]->hasField($property) || $ret[0]->hasAssociation($property)) { diff --git a/Tests/Validator/Constraints/UniqueTest.php b/Tests/Validator/Constraints/UniqueTest.php index 374de46f..0ba575c5 100644 --- a/Tests/Validator/Constraints/UniqueTest.php +++ b/Tests/Validator/Constraints/UniqueTest.php @@ -7,9 +7,7 @@ use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; - -use function assert; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; final class UniqueTest extends TestCase { @@ -17,18 +15,17 @@ public function testWithDefaultProperty(): void { $metadata = new ClassMetadata(UniqueDocumentDummyOne::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$constraint] = $metadata->getConstraints(); - assert($constraint instanceof Unique); + self::assertInstanceOf(Unique::class, $constraint); self::assertSame(['email'], $constraint->fields); self::assertSame('doctrine_odm.mongodb.unique', $constraint->validatedBy()); } } -/** @Unique(fields={"email"}) */ #[Unique(['email'])] class UniqueDocumentDummyOne { diff --git a/composer.json b/composer.json index c1a4eead..86f62cf1 100644 --- a/composer.json +++ b/composer.json @@ -30,27 +30,27 @@ "doctrine/mongodb-odm": "^2.3", "doctrine/persistence": "^2.2 || ^3.0", "psr/log": "^1.0 || ^2.0 || ^3.0", - "symfony/config": "^5.4 || ^6.2", - "symfony/console": "^5.4 || ^6.2", - "symfony/dependency-injection": "^5.4 || ^6.2", + "symfony/config": "^5.4 || ^6.2 || ^7.0", + "symfony/console": "^5.4 || ^6.2 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0", "symfony/deprecation-contracts": "^2.1 || ^3.0", - "symfony/doctrine-bridge": "^5.4.19 || ^6.2", - "symfony/framework-bundle": "^5.4 || ^6.2", - "symfony/http-kernel": "^5.4 || ^6.2", - "symfony/options-resolver": "^5.4 || ^6.2" + "symfony/doctrine-bridge": "^5.4.19 || ^6.2 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.2 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.2 || ^7.0", + "symfony/options-resolver": "^5.4 || ^6.2 || ^7.0" }, "require-dev": { "doctrine/coding-standard": "^11.0", "doctrine/data-fixtures": "^1.3", "phpunit/phpunit": "^9.5.5", "psalm/plugin-symfony": "^5.0", - "symfony/browser-kit": "^5.4 || ^6.2", - "symfony/form": "^5.4 || ^6.2", - "symfony/phpunit-bridge": "^6.2", - "symfony/security-bundle": "^5.4 || ^6.2", - "symfony/stopwatch": "^5.4 || ^6.2", - "symfony/validator": "^5.4 || ^6.2", - "symfony/yaml": "^5.4 || ^6.2", + "symfony/browser-kit": "^5.4 || ^6.2 || ^7.0", + "symfony/form": "^5.4 || ^6.2 || ^7.0", + "symfony/phpunit-bridge": "^6.2 || ^7.0", + "symfony/security-bundle": "^5.4 || ^6.2 || ^7.0", + "symfony/stopwatch": "^5.4 || ^6.2 || ^7.0", + "symfony/validator": "^5.4 || ^6.2 || ^7.0", + "symfony/yaml": "^5.4 || ^6.2 || ^7.0", "vimeo/psalm": "^5.12" }, "conflict": { @@ -59,7 +59,8 @@ "suggest": { "doctrine/data-fixtures": "Load data fixtures" }, - "minimum-stability": "stable", + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Doctrine\\Bundle\\MongoDBBundle\\": "" From 89cd8b16598330169a22075e68d4ef8fba634b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Sun, 10 Dec 2023 19:37:45 +0100 Subject: [PATCH 2/4] Remove support for symfony < 6.4 --- .github/workflows/continuous-integration.yml | 7 ++--- README.markdown | 6 ++-- UPGRADE-5.0.md | 1 + composer.json | 30 ++++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e9533536..817a97eb 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -28,9 +28,8 @@ jobs: stability: - "stable" symfony-version: - - "5.4.*" - "6.4.*" - - "7.0.x" + - "7.0.*" driver-version: - "stable" dependencies: @@ -41,10 +40,10 @@ jobs: php-version: "8.1" driver-version: "1.5.0" stability: "stable" - symfony-version: "5.4.*" + symfony-version: "6.4.*" exclude: - php-version: "8.1" - symfony-version: "7.0.x" + symfony-version: "7.0.*" services: mongodb: diff --git a/README.markdown b/README.markdown index 13b94c27..25a7180c 100644 --- a/README.markdown +++ b/README.markdown @@ -15,8 +15,8 @@ Compatibility The current version of this bundle has the following requirements: * PHP 8.1 or newer is required * `ext-mongodb` 1.5 or newer - * Symfony 5.4 or newer is required + * Symfony 6.4 or newer is required -Support for older Symfony, PHP and MongoDB versions is provided via the `3.0.x` -releases (tracked in the `3.0` branch). This version sees bug and security fixes +Support for older Symfony, PHP and MongoDB versions is provided via the `4.7.x` +releases (tracked in the `4.7.x` branch). This version sees bug and security fixes only. diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 820c1d72..a95f8490 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -1,6 +1,7 @@ UPGRADE FROM 4.x to 5.0 ======================= +* Add support for Symfony 7.0 and require at least Symfony 6.4 * The `doctrine:mongodb:tail-cursor` command and `Doctrine\Bundle\MongoDBBundle\Cursor\TailableCursorProcessorInterface` interface have been dropped. You should use diff --git a/composer.json b/composer.json index 86f62cf1..f86d8560 100644 --- a/composer.json +++ b/composer.json @@ -30,27 +30,27 @@ "doctrine/mongodb-odm": "^2.3", "doctrine/persistence": "^2.2 || ^3.0", "psr/log": "^1.0 || ^2.0 || ^3.0", - "symfony/config": "^5.4 || ^6.2 || ^7.0", - "symfony/console": "^5.4 || ^6.2 || ^7.0", - "symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0", + "symfony/config": "^6.4 || ^7.0", + "symfony/console": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", "symfony/deprecation-contracts": "^2.1 || ^3.0", - "symfony/doctrine-bridge": "^5.4.19 || ^6.2 || ^7.0", - "symfony/framework-bundle": "^5.4 || ^6.2 || ^7.0", - "symfony/http-kernel": "^5.4 || ^6.2 || ^7.0", - "symfony/options-resolver": "^5.4 || ^6.2 || ^7.0" + "symfony/doctrine-bridge": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/options-resolver": "^6.4 || ^7.0" }, "require-dev": { "doctrine/coding-standard": "^11.0", - "doctrine/data-fixtures": "^1.3", + "doctrine/data-fixtures": "^1.7", "phpunit/phpunit": "^9.5.5", "psalm/plugin-symfony": "^5.0", - "symfony/browser-kit": "^5.4 || ^6.2 || ^7.0", - "symfony/form": "^5.4 || ^6.2 || ^7.0", - "symfony/phpunit-bridge": "^6.2 || ^7.0", - "symfony/security-bundle": "^5.4 || ^6.2 || ^7.0", - "symfony/stopwatch": "^5.4 || ^6.2 || ^7.0", - "symfony/validator": "^5.4 || ^6.2 || ^7.0", - "symfony/yaml": "^5.4 || ^6.2 || ^7.0", + "symfony/browser-kit": "^6.4 || ^7.0", + "symfony/form": "^6.4 || ^7.0", + "symfony/phpunit-bridge": "^6.4.1 || ^7.0.1", + "symfony/security-bundle": "^6.4 || ^7.0", + "symfony/stopwatch": "^6.4 || ^7.0", + "symfony/validator": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0", "vimeo/psalm": "^5.12" }, "conflict": { From a53c5ed458fb32451d862bde2f097e2831a9d460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 11 Dec 2023 20:44:56 +0100 Subject: [PATCH 3/4] Revert to stable packages --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f86d8560..fdd0dda1 100644 --- a/composer.json +++ b/composer.json @@ -59,8 +59,7 @@ "suggest": { "doctrine/data-fixtures": "Load data fixtures" }, - "minimum-stability": "dev", - "prefer-stable": true, + "minimum-stability": "stable", "autoload": { "psr-4": { "Doctrine\\Bundle\\MongoDBBundle\\": "" From 628b820a64140c2675308bcc5002310798943a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 12 Dec 2023 21:22:36 +0100 Subject: [PATCH 4/4] Remove compatibility code with Symfony < 6.2 --- .../Compiler/DoctrineMongoDBMappingsPass.php | 2 -- DependencyInjection/DoctrineMongoDBExtension.php | 6 ------ 2 files changed, 8 deletions(-) diff --git a/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php b/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php index 50e85441..574cd605 100644 --- a/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php +++ b/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php @@ -17,8 +17,6 @@ * Class for Symfony bundles to configure mappings for model classes not in the * automapped folder. * - * NOTE: alias is only supported by Symfony 2.6+ and will be ignored with older versions. - * * @internal since version 4.7.0 */ final class DoctrineMongoDBMappingsPass extends RegisterMappingsPass diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index 73ad48a2..cfda1637 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -19,7 +19,6 @@ use Doctrine\Common\EventSubscriber; use Doctrine\ODM\MongoDB\DocumentManager; use InvalidArgumentException; -use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; use Symfony\Component\Cache\Adapter\ApcuAdapter; @@ -400,11 +399,6 @@ private function loadMessengerServices(ContainerBuilder $container): void /** @param array $config */ private function loadEntityValueResolverServices(ContainerBuilder $container, FileLoader $loader, array $config): void { - // available in Symfony 6.2 and higher - if (! class_exists(EntityValueResolver::class)) { - return; - } - $loader->load('value_resolver.xml'); if (! class_exists(ExpressionLanguage::class)) {