diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index df23fe9d..f46a7f3b 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -6,21 +6,32 @@ use Doctrine\Bundle\MongoDBBundle\Attribute\AsDocumentListener; use Doctrine\Bundle\MongoDBBundle\Attribute\MapDocument; +use Doctrine\Bundle\MongoDBBundle\CacheWarmer\HydratorCacheWarmer; +use Doctrine\Bundle\MongoDBBundle\CacheWarmer\PersistentCollectionCacheWarmer; +use Doctrine\Bundle\MongoDBBundle\CacheWarmer\ProxyCacheWarmer; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\FixturesCompilerPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; use Doctrine\Bundle\MongoDBBundle\EventSubscriber\EventSubscriberInterface; use Doctrine\Bundle\MongoDBBundle\Fixture\ODMFixtureInterface; +use Doctrine\Bundle\MongoDBBundle\ManagerConfigurator; +use Doctrine\Bundle\MongoDBBundle\ManagerRegistry; use Doctrine\Bundle\MongoDBBundle\Repository\ServiceDocumentRepositoryInterface; use Doctrine\Common\Cache\MemcacheCache; use Doctrine\Common\Cache\RedisCache; use Doctrine\Common\DataFixtures\Loader as DataFixturesLoader; use Doctrine\Common\EventSubscriber; +use Doctrine\ODM\MongoDB\Configuration as MongoDBConfiguration; use Doctrine\ODM\MongoDB\DocumentManager; use InvalidArgumentException; use Jean85\PrettyVersions; +use MongoDB\Client; use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver; +use Symfony\Bridge\Doctrine\ContainerAwareEventManager; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; +use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator; +use Symfony\Bridge\Doctrine\Validator\DoctrineInitializer; use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\MemcachedAdapter; @@ -46,6 +57,7 @@ use function is_dir; use function reset; use function sprintf; +use function trigger_deprecation; /** * Doctrine MongoDB ODM extension. @@ -147,6 +159,8 @@ public function load(array $configs, ContainerBuilder $container) $this->loadMessengerServices($container); $this->loadEntityValueResolverServices($container, $loader, $config); + + $this->deprecateChangedClassParameters($container); } /** @@ -661,4 +675,35 @@ private static function getODMVersion(): string return self::$odmVersion; } + + private function deprecateChangedClassParameters(ContainerBuilder $container): void + { + foreach ( + [ + '%doctrine_mongodb.odm.connection.class%' => Client::class, + '%doctrine_mongodb.odm.configuration.class%' => MongoDBConfiguration::class, + '%doctrine_mongodb.odm.document_manager.class%' => DocumentManager::class, + '%doctrine_mongodb.odm.manager_configurator.class%' => ManagerConfigurator::class, + '%doctrine_mongodb.odm.event_manager.class%' => ContainerAwareEventManager::class, + '%doctrine_odm.mongodb.validator_initializer.class%' => DoctrineInitializer::class, + '%doctrine_odm.mongodb.validator.unique.class%' => UniqueEntityValidator::class, + '%doctrine_mongodb.odm.class%' => ManagerRegistry::class, + '%doctrine_mongodb.odm.security.user.provider.class%' => EntityUserProvider::class, + '%doctrine_mongodb.odm.proxy_cache_warmer.class%' => ProxyCacheWarmer::class, + '%doctrine_mongodb.odm.hydrator_cache_warmer.class%' => HydratorCacheWarmer::class, + '%doctrine_mongodb.odm.persistent_collection_cache_warmer.class%' => PersistentCollectionCacheWarmer::class, + ] as $parameter => $class + ) { + if (! $container->hasParameter($parameter) || $container->getParameter($parameter) === $class) { + continue; + } + + trigger_deprecation( + 'doctrine/mongodb-odm-bundle', + '4.7', + '"%s" parameter is deprecated, use a compiler pass to update the service instead.', + $parameter, + ); + } + } } diff --git a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php index fbe69742..4db3edc4 100644 --- a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php @@ -8,7 +8,9 @@ use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\DocumentListenerBundle\EventListener\TestAttributeListener; use PHPUnit\Framework\TestCase; +use stdClass; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -25,6 +27,8 @@ class DoctrineMongoDBExtensionTest extends TestCase { + use ExpectDeprecationTrait; + public static function buildConfiguration(array $settings = []): array { return [ @@ -370,4 +374,20 @@ public function testControllerResolver(): void $container->compile(); $this->assertEquals(new MapDocument(null, null, null, [], null, null, null, true), $container->get('controller_resolver_defaults')); } + + /** @group legacy */ + public function testOverrideDeprecatedClassParameters(): void + { + $container = $this->buildMinimalContainer(); + $container->setParameter('kernel.debug', false); + $container->setParameter('kernel.bundles', []); + $container->setParameter('kernel.bundles_metadata', []); + $container->setParameter('%doctrine_mongodb.odm.connection.class%', stdClass::class); + + $loader = new DoctrineMongoDBExtension(); + + $this->expectDeprecation('Since doctrine/mongodb-odm-bundle 4.7: "%doctrine_mongodb.odm.connection.class%" parameter is deprecated, use a compiler pass to update the service instead.'); + + $loader->load(self::buildConfiguration(), $container); + } }