diff --git a/DependencyInjection/Compiler/DeprecateChangesClassParametersPass.php b/DependencyInjection/Compiler/DeprecateChangesClassParametersPass.php new file mode 100644 index 00000000..0a97185c --- /dev/null +++ b/DependencyInjection/Compiler/DeprecateChangesClassParametersPass.php @@ -0,0 +1,57 @@ + Client::class, + 'doctrine_mongodb.odm.configuration.class' => Configuration::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/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index e52afe28..54da013f 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -55,7 +55,6 @@ use function in_array; use function interface_exists; use function is_dir; -use function method_exists; use function reset; use function sprintf; @@ -159,8 +158,6 @@ public function load(array $configs, ContainerBuilder $container) $this->loadMessengerServices($container); $this->loadEntityValueResolverServices($container, $loader, $config); - - $this->deprecateClassParameters($container); } /** @@ -675,35 +672,4 @@ private static function getODMVersion(): string return self::$odmVersion; } - - private function deprecateClassParameters(ContainerBuilder $container): void - { - if (! method_exists($container, 'deprecateParameter')) { - return; - } - - 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 - ) { - $container->deprecateParameter( - $parameter, - 'doctrine/mongodb-odm-bundle', - '4.7', - '"%s" parameter is deprecated, you should use a compiler pass to update the service instead.', - ); - } - } } diff --git a/DoctrineMongoDBBundle.php b/DoctrineMongoDBBundle.php index bd88f530..f3ea1d72 100644 --- a/DoctrineMongoDBBundle.php +++ b/DoctrineMongoDBBundle.php @@ -7,6 +7,7 @@ use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\CacheCompatibilityPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\CreateHydratorDirectoryPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\CreateProxyDirectoryPass; +use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DeprecateChangesClassParametersPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\FixturesCompilerPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; @@ -43,6 +44,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new DoctrineValidationPass('mongodb')); $container->addCompilerPass(new ServiceRepositoryCompilerPass()); $container->addCompilerPass(new FixturesCompilerPass()); + $container->addCompilerPass(new DeprecateChangesClassParametersPass()); if (! $container->hasExtension('security')) { return; diff --git a/Tests/DependencyInjection/Compiler/DeprecateChangesClassParametersPassTest.php b/Tests/DependencyInjection/Compiler/DeprecateChangesClassParametersPassTest.php new file mode 100644 index 00000000..02b67629 --- /dev/null +++ b/Tests/DependencyInjection/Compiler/DeprecateChangesClassParametersPassTest.php @@ -0,0 +1,29 @@ +setParameter('doctrine_mongodb.odm.connection.class', stdClass::class); + + $container->addCompilerPass(new DeprecateChangesClassParametersPass()); + + $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.'); + + $container->compile(); + } +}