From 573531e89960844626bd90ac0539c8b48cae38cf Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 13 Dec 2023 13:47:39 +0100 Subject: [PATCH 1/3] Migrate config to PHP --- .../DoctrineMongoDBExtension.php | 22 +- Resources/config/cache_warmer.php | 32 +++ Resources/config/command.php | 57 ++++++ Resources/config/form.php | 25 +++ Resources/config/logger.php | 34 ++++ Resources/config/messenger.php | 18 ++ Resources/config/messenger.xml | 13 -- Resources/config/mongodb.php | 91 +++++++++ Resources/config/mongodb.xml | 188 ------------------ Resources/config/profiler.php | 19 ++ Resources/config/validator.php | 25 +++ Resources/config/value_resolver.php | 28 +++ Resources/config/value_resolver.xml | 20 -- .../AbstractMongoDBExtensionTestCase.php | 3 - 14 files changed, 342 insertions(+), 233 deletions(-) create mode 100644 Resources/config/cache_warmer.php create mode 100644 Resources/config/command.php create mode 100644 Resources/config/form.php create mode 100644 Resources/config/logger.php create mode 100644 Resources/config/messenger.php delete mode 100644 Resources/config/messenger.xml create mode 100644 Resources/config/mongodb.php delete mode 100644 Resources/config/mongodb.xml create mode 100644 Resources/config/profiler.php create mode 100644 Resources/config/validator.php create mode 100644 Resources/config/value_resolver.php delete mode 100644 Resources/config/value_resolver.xml diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index cfda1637..872c19f0 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -31,7 +31,7 @@ use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\Messenger\MessageBusInterface; @@ -62,13 +62,18 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension */ public function load(array $configs, ContainerBuilder $container): void { - // Load DoctrineMongoDBBundle/Resources/config/mongodb.xml - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader->load('mongodb.xml'); + $loader->load('mongodb.php'); + $loader->load('cache_warmer.php'); + $loader->load('command.php'); + $loader->load('form.php'); + $loader->load('logger.php'); + $loader->load('profiler.php'); + $loader->load('validator.php'); if (empty($config['default_connection'])) { $keys = array_keys($config['connections']); @@ -143,7 +148,7 @@ public function load(array $configs, ContainerBuilder $container): void ]); }); - $this->loadMessengerServices($container); + $this->loadMessengerServices($container, $loader); $this->loadEntityValueResolverServices($container, $loader, $config); } @@ -385,21 +390,20 @@ protected function loadConnections(array $connections, ContainerBuilder $contain $container->setParameter('doctrine_mongodb.odm.connections', $cons); } - private function loadMessengerServices(ContainerBuilder $container): void + private function loadMessengerServices(ContainerBuilder $container, FileLoader $loader): void { /** @psalm-suppress UndefinedClass Optional dependency */ if (! interface_exists(MessageBusInterface::class) || ! class_exists(DoctrineClearEntityManagerWorkerSubscriber::class)) { return; } - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('messenger.xml'); + $loader->load('messenger.php'); } /** @param array $config */ private function loadEntityValueResolverServices(ContainerBuilder $container, FileLoader $loader, array $config): void { - $loader->load('value_resolver.xml'); + $loader->load('value_resolver.php'); if (! class_exists(ExpressionLanguage::class)) { $container->removeDefinition('doctrine_mongodb.odm.document_value_resolver.expression_language'); diff --git a/Resources/config/cache_warmer.php b/Resources/config/cache_warmer.php new file mode 100644 index 00000000..38d8181c --- /dev/null +++ b/Resources/config/cache_warmer.php @@ -0,0 +1,32 @@ +services() + + ->set('doctrine_mongodb.odm.proxy_cache_warmer', ProxyCacheWarmer::class) + ->tag('kernel.cache_warmer', ['priority' => 25]) + ->args([ + service('service_container'), + ]) + + ->set('doctrine_mongodb.odm.hydrator_cache_warmer', HydratorCacheWarmer::class) + ->tag('kernel.cache_warmer', ['priority' => 25]) + ->args([ + service('service_container'), + ]) + + ->set('doctrine_mongodb.odm.persistent_collection_cache_warmer', PersistentCollectionCacheWarmer::class) + ->tag('kernel.cache_warmer', ['priority' => 25]) + ->args([ + service('service_container'), + ]); +}; diff --git a/Resources/config/command.php b/Resources/config/command.php new file mode 100644 index 00000000..01e4e744 --- /dev/null +++ b/Resources/config/command.php @@ -0,0 +1,57 @@ +services() + ->set('doctrine_mongodb.odm.command.clear_metadata_cache', ClearMetadataCacheDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:cache:clear-metadata']) + + ->set('doctrine_mongodb.odm.command.create_schema', CreateSchemaDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:schema:create']) + + ->set('doctrine_mongodb.odm.command.drop_schema', DropSchemaDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:schema:drop']) + + ->set('doctrine_mongodb.odm.command.generate_hydrators', GenerateHydratorsDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:generate:hydrators']) + + ->set('doctrine_mongodb.odm.command.generate_proxies', GenerateProxiesDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:generate:proxies']) + + ->set('doctrine_mongodb.odm.command.info', InfoDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:mapping:info']) + ->args([ + service('doctrine_mongodb'), + ]) + + ->set('doctrine_mongodb.odm.command.load_data_fixtures', LoadDataFixturesDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:fixtures:load']) + ->args([ + service('doctrine_mongodb'), + service('doctrine_mongodb.odm.symfony.fixtures.loader'), + ]) + + ->set('doctrine_mongodb.odm.command.query', QueryDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:query']) + + ->set('doctrine_mongodb.odm.command.shard', ShardDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:schema:shard']) + + ->set('doctrine_mongodb.odm.command.update_schema', UpdateSchemaDoctrineODMCommand::class) + ->tag('console.command', ['command' => 'doctrine:mongodb:schema:update']); +}; diff --git a/Resources/config/form.php b/Resources/config/form.php new file mode 100644 index 00000000..647e4a53 --- /dev/null +++ b/Resources/config/form.php @@ -0,0 +1,25 @@ +services() + + ->set('form.type.mongodb_document', DocumentType::class) + ->tag('form.type', ['alias' => 'document']) + ->args([ + service('doctrine_mongodb'), + ]) + + ->set('form.type_guesser.doctrine.mongodb', DoctrineMongoDBTypeGuesser::class) + ->tag('form.type_guesser') + ->args([ + service('doctrine_mongodb'), + ]); +}; diff --git a/Resources/config/logger.php b/Resources/config/logger.php new file mode 100644 index 00000000..5c2f6ff9 --- /dev/null +++ b/Resources/config/logger.php @@ -0,0 +1,34 @@ +services() + + ->set('doctrine_mongodb.odm.command_logger_registry', CommandLoggerRegistry::class) + ->public() + ->args([ + tagged_iterator('doctrine_mongodb.odm.command_logger'), + ]) + + ->set('doctrine_mongodb.odm.stopwatch_command_logger', StopwatchCommandLogger::class) + ->args([ + service('debug.stopwatch')->nullOnInvalid(), + ]) + + ->set('doctrine_mongodb.odm.psr_command_logger', PSRCommandLogger::class) + ->tag('monolog.logger', ['channel' => 'doctrine']) + ->args([ + service('logger')->nullOnInvalid(), + ]) + + ->alias('doctrine_mongodb.odm.command_logger', 'doctrine_mongodb.odm.psr_command_logger'); +}; diff --git a/Resources/config/messenger.php b/Resources/config/messenger.php new file mode 100644 index 00000000..c3fdd90a --- /dev/null +++ b/Resources/config/messenger.php @@ -0,0 +1,18 @@ +services(); + + $services->set('doctrine_mongodb.messenger.event_subscriber.doctrine_clear_document_manager', DoctrineClearEntityManagerWorkerSubscriber::class) + ->tag('kernel.event_subscriber') + ->args([ + service('doctrine_mongodb'), + ]); +}; diff --git a/Resources/config/messenger.xml b/Resources/config/messenger.xml deleted file mode 100644 index d50cd761..00000000 --- a/Resources/config/messenger.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - diff --git a/Resources/config/mongodb.php b/Resources/config/mongodb.php new file mode 100644 index 00000000..932f9509 --- /dev/null +++ b/Resources/config/mongodb.php @@ -0,0 +1,91 @@ +parameters() + ->set('doctrine_mongodb.odm.cache.array.class', 'Doctrine\Common\Cache\ArrayCache') + ->set('doctrine_mongodb.odm.cache.apc.class', 'Doctrine\Common\Cache\ApcCache') + ->set('doctrine_mongodb.odm.cache.apcu.class', 'Doctrine\Common\Cache\ApcuCache') + ->set('doctrine_mongodb.odm.cache.memcache.class', 'Doctrine\Common\Cache\MemcacheCache') + ->set('doctrine_mongodb.odm.cache.memcache_host', 'localhost') + ->set('doctrine_mongodb.odm.cache.memcache_port', 11211) + ->set('doctrine_mongodb.odm.cache.memcache_instance.class', 'Memcache') + ->set('doctrine_mongodb.odm.cache.xcache.class', 'Doctrine\Common\Cache\XcacheCache') + ->set('doctrine_mongodb.odm.connection.class', Client::class) + ->set('doctrine_mongodb.odm.configuration.class', Configuration::class) + ->set('doctrine_mongodb.odm.document_manager.class', DocumentManager::class) + ->set('doctrine_mongodb.odm.manager_configurator.class', ManagerConfigurator::class) + ->set('doctrine_mongodb.odm.class', ManagerRegistry::class) + ->set('doctrine_mongodb.odm.metadata.driver_chain.class', MappingDriverChain::class) + ->set('doctrine_mongodb.odm.metadata.attribute.class', AttributeDriver::class) + ->set('doctrine_mongodb.odm.metadata.xml.class', XmlDriver::class) + ->set('doctrine_mongodb.odm.mapping_dirs', []) + ->set('doctrine_mongodb.odm.xml_mapping_dirs', '%doctrine_mongodb.odm.mapping_dirs%') + ->set('doctrine_mongodb.odm.document_dirs', []) + ->set('doctrine_mongodb.odm.fixtures_dirs', []); + + $containerConfigurator->services() + + ->alias(DocumentManager::class, 'doctrine_mongodb.odm.document_manager') + + ->alias(ManagerRegistry::class, 'doctrine_mongodb') + + ->set('doctrine_mongodb.odm.connection.event_manager', ContainerAwareEventManager::class) + ->abstract() + ->args([ + service('service_container'), + ]) + + ->set('doctrine_mongodb.odm.container_repository_factory', ContainerRepositoryFactory::class) + ->args([ + abstract_arg('service locator'), + ]) + + ->set('doctrine_mongodb.odm.manager_configurator.abstract', ManagerConfigurator::class) + ->abstract() + ->args([ + abstract_arg('enabled filters'), + ]) + + ->set('doctrine_mongodb.odm.security.user.provider', EntityUserProvider::class) + ->abstract() + ->args([ + service('doctrine_mongodb'), + ]) + + ->set('doctrine_mongodb', '%doctrine_mongodb.odm.class%') + ->public() + ->args([ + 'MongoDB', + '%doctrine_mongodb.odm.connections%', + '%doctrine_mongodb.odm.document_managers%', + '%doctrine_mongodb.odm.default_connection%', + '%doctrine_mongodb.odm.default_document_manager%', + GhostObjectInterface::class, + service('service_container'), + ]) + + ->set('doctrine_mongodb.odm.listeners.resolve_target_document', ResolveTargetDocumentListener::class) + + ->set('doctrine_mongodb.odm.symfony.fixtures.loader', SymfonyFixturesLoader::class); +}; diff --git a/Resources/config/mongodb.xml b/Resources/config/mongodb.xml deleted file mode 100644 index 0cf838b6..00000000 --- a/Resources/config/mongodb.xml +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - MongoDB\Client - Doctrine\ODM\MongoDB\Configuration - Doctrine\ODM\MongoDB\DocumentManager - Doctrine\Bundle\MongoDBBundle\ManagerConfigurator - Symfony\Bridge\Doctrine\ContainerAwareEventManager - Symfony\Bridge\Doctrine\Validator\DoctrineInitializer - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator - Doctrine\Bundle\MongoDBBundle\ManagerRegistry - Symfony\Bridge\Doctrine\Security\User\EntityUserProvider - Doctrine\Bundle\MongoDBBundle\CacheWarmer\ProxyCacheWarmer - Doctrine\Bundle\MongoDBBundle\CacheWarmer\HydratorCacheWarmer - Doctrine\Bundle\MongoDBBundle\CacheWarmer\PersistentCollectionCacheWarmer - - - Doctrine\Common\Cache\ArrayCache - Doctrine\Common\Cache\ApcCache - Doctrine\Common\Cache\ApcuCache - Doctrine\Common\Cache\MemcacheCache - localhost - 11211 - Memcache - Doctrine\Common\Cache\XcacheCache - - - Doctrine\Persistence\Mapping\Driver\MappingDriverChain - Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver - Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver - - - - %doctrine_mongodb.odm.mapping_dirs% - - - - - 4 - - - Doctrine\ODM\MongoDB\Tools\ResolveTargetDocumentListener - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MongoDB - %doctrine_mongodb.odm.connections% - %doctrine_mongodb.odm.document_managers% - %doctrine_mongodb.odm.default_connection% - %doctrine_mongodb.odm.default_document_manager% - ProxyManager\Proxy\GhostObjectInterface - - - - - - - - - diff --git a/Resources/config/profiler.php b/Resources/config/profiler.php new file mode 100644 index 00000000..af3e944a --- /dev/null +++ b/Resources/config/profiler.php @@ -0,0 +1,19 @@ +services() + ->set('doctrine_mongodb.odm.data_collector.command_logger', CommandLogger::class) + + ->set('doctrine_mongodb.odm.data_collector', CommandDataCollector::class) + ->args([ + service('doctrine_mongodb.odm.data_collector.command_logger'), + ]); +}; diff --git a/Resources/config/validator.php b/Resources/config/validator.php new file mode 100644 index 00000000..6351359b --- /dev/null +++ b/Resources/config/validator.php @@ -0,0 +1,25 @@ +services() + + ->set('doctrine_odm.mongodb.validator.unique', UniqueEntityValidator::class) + ->tag('validator.constraint_validator', ['alias' => 'doctrine_odm.mongodb.unique']) + ->args([ + service('doctrine_mongodb'), + ]) + + ->set('doctrine_odm.mongodb.validator_initializer', DoctrineInitializer::class) + ->tag('validator.initializer') + ->args([ + service('doctrine_mongodb'), + ]); +}; diff --git a/Resources/config/value_resolver.php b/Resources/config/value_resolver.php new file mode 100644 index 00000000..3ed803ea --- /dev/null +++ b/Resources/config/value_resolver.php @@ -0,0 +1,28 @@ +services(); + + $services->set('doctrine_mongodb.odm.entity_value_resolver', EntityValueResolver::class) + ->args([ + service('doctrine_mongodb'), + service('doctrine_mongodb.odm.document_value_resolver.expression_language')->ignoreOnInvalid(), + ]); + + $services->set('doctrine_mongodb.odm.document_value_resolver.expression_language', ExpressionLanguage::class); + + $services->set('doctrine_mongodb.odm.document_value_resolver', DocumentValueResolver::class) + ->tag('controller.argument_value_resolver', ['name' => DocumentValueResolver::class, 'priority' => 110]) + ->args([ + service('doctrine_mongodb.odm.entity_value_resolver'), + ]); +}; diff --git a/Resources/config/value_resolver.xml b/Resources/config/value_resolver.xml deleted file mode 100644 index 92fcd9e6..00000000 --- a/Resources/config/value_resolver.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - controller.argument_value_resolver - - - diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index 1376052c..c4a4ac46 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -22,7 +22,6 @@ use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use MongoDB\Client; use PHPUnit\Framework\AssertionFailedError; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -66,8 +65,6 @@ public function testDependencyInjectionConfigurationDefaults(): void $this->assertEquals(AttributeDriver::class, $container->getParameter('doctrine_mongodb.odm.metadata.attribute.class')); $this->assertEquals(XmlDriver::class, $container->getParameter('doctrine_mongodb.odm.metadata.xml.class')); - $this->assertEquals(UniqueEntityValidator::class, $container->getParameter('doctrine_odm.mongodb.validator.unique.class')); - $config = DoctrineMongoDBExtensionTest::buildConfiguration([ 'proxy_namespace' => 'MyProxies', 'auto_generate_proxy_classes' => true, From 62b1ab97083679ec9315a554779c46fd5851609b Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 13 Dec 2023 17:18:00 +0100 Subject: [PATCH 2/3] Remove deprecated alias --- DependencyInjection/DoctrineMongoDBExtension.php | 7 ------- Resources/config/logger.php | 4 +--- Tests/ContainerTest.php | 3 --- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index 872c19f0..14e1ba48 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -265,13 +265,6 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa $methods['setPersistentCollectionFactory'] = new Reference($documentManager['persistent_collection_factory']); } - $container->getAlias('doctrine_mongodb.odm.command_logger') - ->setDeprecated( - 'doctrine/mongodb-odm-bundle', - '4.4', - 'The service %alias_id% is deprecated and will be dropped in DoctrineMongoDBBundle 5.0. Use "doctrine_mongodb.odm.psr_command_logger" instead.', - ); - // logging if ($container->getParameterBag()->resolveValue($documentManager['logging'])) { $container->getDefinition('doctrine_mongodb.odm.psr_command_logger') diff --git a/Resources/config/logger.php b/Resources/config/logger.php index 5c2f6ff9..4b70fc92 100644 --- a/Resources/config/logger.php +++ b/Resources/config/logger.php @@ -28,7 +28,5 @@ ->tag('monolog.logger', ['channel' => 'doctrine']) ->args([ service('logger')->nullOnInvalid(), - ]) - - ->alias('doctrine_mongodb.odm.command_logger', 'doctrine_mongodb.odm.psr_command_logger'); + ]); }; diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index ae2e4c94..628a90b1 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -87,9 +87,6 @@ public function testDataCollectorConfig(bool $expected, array $config, bool $deb $this->container->setParameter('kernel.debug', $debug); $this->extension->load([$config], $this->container); - $deprecatedLoggerDefinition = $this->container->getAlias('doctrine_mongodb.odm.command_logger'); - $this->assertTrue($deprecatedLoggerDefinition->isDeprecated()); - $loggerDefinition = $this->container->getDefinition('doctrine_mongodb.odm.data_collector.command_logger'); $this->assertSame($expected, $loggerDefinition->hasTag('doctrine_mongodb.odm.command_logger')); From 3fe3ece094008ccc4da45b6e81925d855033716c Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 13 Dec 2023 21:54:05 +0100 Subject: [PATCH 3/3] Remove unused and .class parameters --- .../DoctrineMongoDBExtension.php | 12 +++--- Resources/config/mongodb.php | 15 +------ .../AbstractMongoDBExtensionTestCase.php | 39 +++++++++---------- 3 files changed, 27 insertions(+), 39 deletions(-) diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index 14e1ba48..6845f4a0 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -17,8 +17,10 @@ use Doctrine\Common\Cache\RedisCache; use Doctrine\Common\DataFixtures\Loader as DataFixturesLoader; use Doctrine\Common\EventSubscriber; +use Doctrine\ODM\MongoDB\Configuration as ODMConfiguration; use Doctrine\ODM\MongoDB\DocumentManager; use InvalidArgumentException; +use MongoDB\Client; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; use Symfony\Component\Cache\Adapter\ApcuAdapter; @@ -229,7 +231,7 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa $configurationId = sprintf('doctrine_mongodb.odm.%s_configuration', $documentManager['name']); $defaultDatabase = $documentManager['database'] ?? $defaultDB; - $odmConfigDef = new Definition('%doctrine_mongodb.odm.configuration.class%'); + $odmConfigDef = new Definition(ODMConfiguration::class); $odmConfigDef->addTag(self::CONFIGURATION_TAG); $container->setDefinition( $configurationId, @@ -318,8 +320,8 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa // Document managers will share their connection's event manager new Reference(sprintf('doctrine_mongodb.odm.%s_connection.event_manager', $connectionName)), ]; - $odmDmDef = new Definition('%doctrine_mongodb.odm.document_manager.class%', $odmDmArgs); - $odmDmDef->setFactory(['%doctrine_mongodb.odm.document_manager.class%', 'create']); + $odmDmDef = new Definition(DocumentManager::class, $odmDmArgs); + $odmDmDef->setFactory([DocumentManager::class, 'create']); $odmDmDef->addTag('doctrine_mongodb.odm.document_manager'); $odmDmDef->setPublic(true); @@ -363,7 +365,7 @@ protected function loadConnections(array $connections, ContainerBuilder $contain $configurationId = sprintf('doctrine_mongodb.odm.%s_configuration', $name); $container->setDefinition( $configurationId, - new Definition('%doctrine_mongodb.odm.configuration.class%'), + new Definition(ODMConfiguration::class), ); $odmConnArgs = [ @@ -373,7 +375,7 @@ protected function loadConnections(array $connections, ContainerBuilder $contain $this->normalizeDriverOptions($connection), ]; - $odmConnDef = new Definition('%doctrine_mongodb.odm.connection.class%', $odmConnArgs); + $odmConnDef = new Definition(Client::class, $odmConnArgs); $odmConnDef->setPublic(true); $id = sprintf('doctrine_mongodb.odm.%s_connection', $name); $container->setDefinition($id, $odmConnDef); diff --git a/Resources/config/mongodb.php b/Resources/config/mongodb.php index 932f9509..16c36cb0 100644 --- a/Resources/config/mongodb.php +++ b/Resources/config/mongodb.php @@ -7,12 +7,10 @@ use Doctrine\Bundle\MongoDBBundle\ManagerRegistry; use Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver; use Doctrine\Bundle\MongoDBBundle\Repository\ContainerRepositoryFactory; -use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; use Doctrine\ODM\MongoDB\Tools\ResolveTargetDocumentListener; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use MongoDB\Client; use ProxyManager\Proxy\GhostObjectInterface; use Symfony\Bridge\Doctrine\ContainerAwareEventManager; use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider; @@ -31,18 +29,9 @@ ->set('doctrine_mongodb.odm.cache.memcache_port', 11211) ->set('doctrine_mongodb.odm.cache.memcache_instance.class', 'Memcache') ->set('doctrine_mongodb.odm.cache.xcache.class', 'Doctrine\Common\Cache\XcacheCache') - ->set('doctrine_mongodb.odm.connection.class', Client::class) - ->set('doctrine_mongodb.odm.configuration.class', Configuration::class) - ->set('doctrine_mongodb.odm.document_manager.class', DocumentManager::class) - ->set('doctrine_mongodb.odm.manager_configurator.class', ManagerConfigurator::class) - ->set('doctrine_mongodb.odm.class', ManagerRegistry::class) ->set('doctrine_mongodb.odm.metadata.driver_chain.class', MappingDriverChain::class) ->set('doctrine_mongodb.odm.metadata.attribute.class', AttributeDriver::class) - ->set('doctrine_mongodb.odm.metadata.xml.class', XmlDriver::class) - ->set('doctrine_mongodb.odm.mapping_dirs', []) - ->set('doctrine_mongodb.odm.xml_mapping_dirs', '%doctrine_mongodb.odm.mapping_dirs%') - ->set('doctrine_mongodb.odm.document_dirs', []) - ->set('doctrine_mongodb.odm.fixtures_dirs', []); + ->set('doctrine_mongodb.odm.metadata.xml.class', XmlDriver::class); $containerConfigurator->services() @@ -73,7 +62,7 @@ service('doctrine_mongodb'), ]) - ->set('doctrine_mongodb', '%doctrine_mongodb.odm.class%') + ->set('doctrine_mongodb', ManagerRegistry::class) ->public() ->args([ 'MongoDB', diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index c4a4ac46..889f8828 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -49,9 +49,6 @@ public function testDependencyInjectionConfigurationDefaults(): void $loader->load(DoctrineMongoDBExtensionTest::buildConfiguration(), $container); - $this->assertEquals(Client::class, $container->getParameter('doctrine_mongodb.odm.connection.class')); - $this->assertEquals(Configuration::class, $container->getParameter('doctrine_mongodb.odm.configuration.class')); - $this->assertEquals(DocumentManager::class, $container->getParameter('doctrine_mongodb.odm.document_manager.class')); $this->assertEquals('MongoDBODMProxies', $container->getParameter('doctrine_mongodb.odm.proxy_namespace')); $this->assertEquals(Configuration::AUTOGENERATE_EVAL, $container->getParameter('doctrine_mongodb.odm.auto_generate_proxy_classes')); $this->assertEquals(ArrayCache::class, $container->getParameter('doctrine_mongodb.odm.cache.array.class')); @@ -77,7 +74,7 @@ public function testDependencyInjectionConfigurationDefaults(): void $this->assertEquals(true, $container->getParameter('doctrine_mongodb.odm.auto_generate_proxy_classes')); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals(null, $arguments[0]); @@ -86,8 +83,8 @@ public function testDependencyInjectionConfigurationDefaults(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -115,7 +112,7 @@ public function testSingleDocumentManagerConfiguration(): void $loader->load([$config], $container); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -126,8 +123,8 @@ public function testSingleDocumentManagerConfiguration(): void $this->assertEquals(new Reference('my_context'), $arguments[2]['context']); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -150,7 +147,7 @@ public function testLoadSimpleSingleConnection(): void $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -165,8 +162,8 @@ public function testLoadSimpleSingleConnection(): void $this->assertEquals('mydb', $methodCalls[$pos][1][0]); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -192,7 +189,7 @@ public function testLoadSingleConnection(): void $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -201,8 +198,8 @@ public function testLoadSingleConnection(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -228,7 +225,7 @@ public function testLoadMultipleConnections(): void $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.conn1_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -237,8 +234,8 @@ public function testLoadMultipleConnections(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.dm1_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -248,7 +245,7 @@ public function testLoadMultipleConnections(): void $this->assertEquals('doctrine_mongodb.odm.dm1_configuration', (string) $arguments[1]); $definition = $container->getDefinition('doctrine_mongodb.odm.conn2_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -257,8 +254,8 @@ public function testLoadMultipleConnections(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.dm2_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments();