From fa5f7df0e3d704a44b8ed631fb791f698aa4df34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 11 Dec 2023 17:25:38 +0100 Subject: [PATCH 1/5] Drop support for Doctrine cache adapter for metadata --- .../Compiler/CacheCompatibilityPass.php | 100 ------------------ DoctrineMongoDBBundle.php | 2 - .../Compiler/CacheCompatibilityPassTest.php | 75 ------------- UPGRADE-5.0.md | 1 + 4 files changed, 1 insertion(+), 177 deletions(-) delete mode 100644 DependencyInjection/Compiler/CacheCompatibilityPass.php delete mode 100644 Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php diff --git a/DependencyInjection/Compiler/CacheCompatibilityPass.php b/DependencyInjection/Compiler/CacheCompatibilityPass.php deleted file mode 100644 index 31bf2162..00000000 --- a/DependencyInjection/Compiler/CacheCompatibilityPass.php +++ /dev/null @@ -1,100 +0,0 @@ - true]; - - public function process(ContainerBuilder $container): void - { - foreach (array_keys($container->findTaggedServiceIds(DoctrineMongoDBExtension::CONFIGURATION_TAG)) as $id) { - /** @var array{0: string, 1: mixed[]} $methodCall */ - foreach ($container->getDefinition($id)->getMethodCalls() as $methodCall) { - $methodName = $methodCall[0]; - - if (! isset(self::CACHE_SETTER_METHODS_PSR6_SUPPORT[$methodName])) { - continue; - } - - $methodArgs = $methodCall[1]; - $definitionId = (string) $methodArgs[0]; - $aliasId = null; - if ($container->hasAlias($definitionId)) { - $aliasId = $definitionId; - $definitionId = (string) $container->getAlias($aliasId); - } - - $shouldBePsr6 = self::CACHE_SETTER_METHODS_PSR6_SUPPORT[$methodName]; - - $this->wrapIfNecessary($container, $aliasId, $definitionId, $shouldBePsr6); - } - } - } - - private function createCompatibilityLayerDefinition(ContainerBuilder $container, string $definitionId, bool $shouldBePsr6): ?Definition - { - $definition = $container->getDefinition($definitionId); - - while (! $definition->getClass() && $definition instanceof ChildDefinition) { - $definition = $container->findDefinition($definition->getParent()); - } - - if ($shouldBePsr6 === is_a($definition->getClass(), CacheItemPoolInterface::class, true)) { - return null; - } - - $targetClass = CacheProvider::class; - $targetFactory = DoctrineProvider::class; - - if ($shouldBePsr6) { - $targetClass = CacheItemPoolInterface::class; - $targetFactory = CacheAdapter::class; - - trigger_deprecation( - 'doctrine/mongodb-odm-bundle', - '4.4', - 'Configuring doctrine/cache is deprecated. Please update the cache service "%s" to use a PSR-6 cache.', - $definitionId, - ); - } - - return (new Definition($targetClass)) - ->setFactory([$targetFactory, 'wrap']) - ->addArgument(new Reference($definitionId)); - } - - private function wrapIfNecessary(ContainerBuilder $container, ?string $aliasId, string $definitionId, bool $shouldBePsr6): void - { - $compatibilityLayer = $this->createCompatibilityLayerDefinition($container, $definitionId, $shouldBePsr6); - - if ($compatibilityLayer === null) { - return; - } - - $aliasId ??= $definitionId; - - $compatibilityLayerId = $definitionId . '.compatibility_layer'; - $container->setDefinition($compatibilityLayerId, $compatibilityLayer); - - $container->setAlias($aliasId, $compatibilityLayerId); - } -} diff --git a/DoctrineMongoDBBundle.php b/DoctrineMongoDBBundle.php index c168fdf5..4c656e8a 100644 --- a/DoctrineMongoDBBundle.php +++ b/DoctrineMongoDBBundle.php @@ -4,7 +4,6 @@ namespace Doctrine\Bundle\MongoDBBundle; -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\FixturesCompilerPass; @@ -35,7 +34,6 @@ class DoctrineMongoDBBundle extends Bundle public function build(ContainerBuilder $container): void { - $container->addCompilerPass(new CacheCompatibilityPass()); $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass('doctrine_mongodb.odm.connections', 'doctrine_mongodb.odm.%s_connection.event_manager', 'doctrine_mongodb.odm'), PassConfig::TYPE_BEFORE_OPTIMIZATION); $container->addCompilerPass(new CreateProxyDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING); $container->addCompilerPass(new CreateHydratorDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING); diff --git a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php deleted file mode 100644 index 8dab24d5..00000000 --- a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php +++ /dev/null @@ -1,75 +0,0 @@ -booted; - } - - public function registerContainerConfiguration(LoaderInterface $loader): void - { - parent::registerContainerConfiguration($loader); - $loader->load(static function (ContainerBuilder $containerBuilder): void { - $containerBuilder->loadFromExtension( - 'doctrine_mongodb', - ['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]], - ); - $containerBuilder->setDefinition( - 'custom_cache_service', - new Definition(ArrayAdapter::class), - ); - }); - } - }); - - $kernel->boot(); - self::assertTrue($kernel->isBooted()); - } - - /** - * @group legacy - * @doesNotPerformAssertions - */ - public function testMetadataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void - { - $this->expectDeprecation('Since doctrine/mongodb-odm-bundle 4.4: Configuring doctrine/cache is deprecated. Please update the cache service "custom_cache_service" to use a PSR-6 cache.'); - (new class (false) extends TestKernel { - public function registerContainerConfiguration(LoaderInterface $loader): void - { - parent::registerContainerConfiguration($loader); - $loader->load(static function (ContainerBuilder $containerBuilder): void { - $containerBuilder->loadFromExtension( - 'doctrine_mongodb', - ['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]], - ); - $containerBuilder->setDefinition( - 'custom_cache_service', - (new Definition(DoctrineProvider::class)) - ->setArguments([new Definition(ArrayAdapter::class)]) - ->setFactory([DoctrineProvider::class, 'wrap']), - ); - }); - } - })->boot(); - } -} diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index a95f8490..8e259fe3 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -17,3 +17,4 @@ UPGRADE FROM 4.x to 5.0 * Remove automatic injection of the container in fixtures classes implementing `ContainerAwareInterface`. You should use dependency injection instead. * Remove the `fixture_loader` configuration +* Metadata cache use a PSR-6 cache pool. Support for Doctrine Cache is dropped. From c5057f3201362d99607d51b81655bfd68c4c8319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 19 Dec 2023 15:30:09 +0100 Subject: [PATCH 2/5] - --- .../DoctrineMongoDBExtension.php | 42 +++++++++---------- Resources/config/mongodb.xml | 14 ------- Resources/doc/config.rst | 4 +- .../AbstractMongoDBExtensionTestCase.php | 32 ++++---------- .../DependencyInjection/ConfigurationTest.php | 2 +- .../Fixtures/config/xml/full.xml | 2 +- .../mongodb_service_multiple_connections.xml | 4 +- ...ngodb_service_simple_single_connection.xml | 2 +- .../Fixtures/config/yml/full.yml | 2 +- .../mongodb_service_multiple_connections.yml | 4 +- ...ngodb_service_simple_single_connection.yml | 2 +- .../yml/mongodb_service_single_connection.yml | 2 +- 12 files changed, 42 insertions(+), 70 deletions(-) diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index fc4e6be6..bba98479 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -13,8 +13,6 @@ use Doctrine\Bundle\MongoDBBundle\EventSubscriber\EventSubscriberInterface; use Doctrine\Bundle\MongoDBBundle\Fixture\ODMFixtureInterface; 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\DocumentManager; @@ -582,13 +580,10 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName, return $cacheDriverServiceId; case 'memcached': - if (! empty($cacheDriver['class']) && $cacheDriver['class'] !== MemcacheCache::class) { - return parent::loadCacheDriver($cacheName, $objectManagerName, $cacheDriver, $container); - } - - $memcachedInstanceClass = ! empty($cacheDriver['instance_class']) ? $cacheDriver['instance_class'] : '%' . $this->getObjectManagerElementName('cache.memcached_instance.class') . '%'; - $memcachedHost = ! empty($cacheDriver['host']) ? $cacheDriver['host'] : '%' . $this->getObjectManagerElementName('cache.memcached_host') . '%'; - $memcachedPort = ! empty($cacheDriver['port']) ? $cacheDriver['port'] : '%' . $this->getObjectManagerElementName('cache.memcached_port') . '%'; + $memcachedClass = $cacheDriver['class'] ?? MemcachedAdapter::class; + $memcachedInstanceClass = $cacheDriver['instance_class'] ?? 'Memcache'; + $memcachedHost = $cacheDriver['host'] ?? 'localhost'; + $memcachedPort = $cacheDriver['port'] ?? '11211'; $memcachedInstance = new Definition($memcachedInstanceClass); $memcachedInstance->addMethodCall('addServer', [ $memcachedHost, @@ -596,18 +591,18 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName, ]); $container->setDefinition($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)), $memcachedInstance); - $cacheDef = new Definition(MemcachedAdapter::class, [new Reference($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)))]); + $cacheDef = new Definition($memcachedClass, [ + new Reference($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName))), + $cacheDriver['namespace'] ?? '', + ]); break; case 'redis': - if (! empty($cacheDriver['class']) && $cacheDriver['class'] !== RedisCache::class) { - return parent::loadCacheDriver($cacheName, $objectManagerName, $cacheDriver, $container); - } - - $redisInstanceClass = ! empty($cacheDriver['instance_class']) ? $cacheDriver['instance_class'] : '%' . $this->getObjectManagerElementName('cache.redis_instance.class') . '%'; - $redisHost = ! empty($cacheDriver['host']) ? $cacheDriver['host'] : '%' . $this->getObjectManagerElementName('cache.redis_host') . '%'; - $redisPort = ! empty($cacheDriver['port']) ? $cacheDriver['port'] : '%' . $this->getObjectManagerElementName('cache.redis_port') . '%'; + $redisClass = $cacheDriver['class'] ?? RedisAdapter::class; + $redisInstanceClass = $cacheDriver['instance_class'] ?? 'Redis'; + $redisHost = $cacheDriver['host'] ?? 'localhost'; + $redisPort = $cacheDriver['port'] ?? '6379'; $redisInstance = new Definition($redisInstanceClass); $redisInstance->addMethodCall('connect', [ $redisHost, @@ -615,22 +610,27 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName, ]); $container->setDefinition($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)), $redisInstance); - $cacheDef = new Definition(RedisAdapter::class, [new Reference($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)))]); + $cacheDef = new Definition($redisClass, [ + new Reference($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName))), + $cacheDriver['namespace'] ?? '', + ]); break; case 'apcu': - $cacheDef = new Definition(ApcuAdapter::class); + $cacheDef = new Definition($cacheDriver['class'] ?? ApcuAdapter::class, [ + $cacheDriver['namespace'] ?? '', + ]); break; case 'array': - $cacheDef = new Definition(ArrayAdapter::class); + $cacheDef = new Definition($cacheDriver['class'] ?? ArrayAdapter::class); break; default: - return parent::loadCacheDriver($cacheName, $objectManagerName, $cacheDriver, $container); + throw new InvalidArgumentException(sprintf('"%s" is an unrecognized cache driver.', $cacheDriver['type'])); } $cacheDef->setPublic(false); diff --git a/Resources/config/mongodb.xml b/Resources/config/mongodb.xml index 0cf838b6..304037ce 100644 --- a/Resources/config/mongodb.xml +++ b/Resources/config/mongodb.xml @@ -19,16 +19,6 @@ 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 @@ -49,7 +39,6 @@ - @@ -113,9 +102,6 @@ - - - diff --git a/Resources/doc/config.rst b/Resources/doc/config.rst index 5435a0a7..cfc3aa01 100644 --- a/Resources/doc/config.rst +++ b/Resources/doc/config.rst @@ -23,7 +23,7 @@ Sample Configuration filter-name: class: Class\Example\Filter\ODM\ExampleFilter enabled: true - metadata_cache_driver: array # array, apc, apcu, memcache, memcached, redis, wincache, zenddata, xcache + metadata_cache_driver: array # array, service, apcu, memcached, redis .. code-block:: xml @@ -86,7 +86,7 @@ If you wish to use memcache to cache your metadata, you need to configure the AcmeDemoBundle: ~ metadata_cache_driver: type: memcache - class: Doctrine\Common\Cache\MemcacheCache + class: Symfony\Component\Cache\Adapter\MemcachedAdapter host: localhost port: 11211 instance_class: Memcache diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index 1376052c..3a109702 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -5,24 +5,20 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; -use Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver; use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Filter\BasicFilter; use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Filter\ComplexFilter; use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Filter\DisabledFilter; use Doctrine\Bundle\MongoDBBundle\Tests\TestCase; -use Doctrine\Common\Cache\ApcCache; -use Doctrine\Common\Cache\ArrayCache; -use Doctrine\Common\Cache\MemcacheCache; -use Doctrine\Common\Cache\MemcachedCache; -use Doctrine\Common\Cache\XcacheCache; use Doctrine\Common\EventSubscriber; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use MongoDB\Client; use PHPUnit\Framework\AssertionFailedError; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator; +use Symfony\Component\Cache\Adapter\ApcuAdapter; +use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Cache\Adapter\MemcachedAdapter; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -55,16 +51,6 @@ public function testDependencyInjectionConfigurationDefaults(): void $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')); - $this->assertEquals(ApcCache::class, $container->getParameter('doctrine_mongodb.odm.cache.apc.class')); - $this->assertEquals(MemcacheCache::class, $container->getParameter('doctrine_mongodb.odm.cache.memcache.class')); - $this->assertEquals('localhost', $container->getParameter('doctrine_mongodb.odm.cache.memcache_host')); - $this->assertEquals('11211', $container->getParameter('doctrine_mongodb.odm.cache.memcache_port')); - $this->assertEquals('Memcache', $container->getParameter('doctrine_mongodb.odm.cache.memcache_instance.class')); - $this->assertEquals(XcacheCache::class, $container->getParameter('doctrine_mongodb.odm.cache.xcache.class')); - $this->assertEquals(MappingDriverChain::class, $container->getParameter('doctrine_mongodb.odm.metadata.driver_chain.class')); - $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')); @@ -349,10 +335,10 @@ public function testDocumentManagerMetadataCacheDriverConfiguration(): void $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.dm1_metadata_cache'); - $this->assertEquals('%doctrine_mongodb.odm.cache.xcache.class%', $definition->getClass()); + $this->assertEquals(ArrayAdapter::class, $definition->getClass()); $definition = $container->getDefinition('doctrine_mongodb.odm.dm2_metadata_cache'); - $this->assertEquals('%doctrine_mongodb.odm.cache.apc.class%', $definition->getClass()); + $this->assertEquals(ApcuAdapter::class, $definition->getClass()); } /** @psalm-suppress UndefinedClass this won't be necessary when removing metadata cache configuration */ @@ -369,11 +355,11 @@ public function testDocumentManagerMemcachedMetadataCacheDriverConfiguration(): $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.default_metadata_cache'); - $this->assertEquals(MemcachedCache::class, $definition->getClass()); + $this->assertEquals(MemcachedAdapter::class, $definition->getClass()); - $calls = $definition->getMethodCalls(); - $this->assertEquals('setMemcached', $calls[0][0]); - $this->assertEquals('doctrine_mongodb.odm.default_memcached_instance', (string) $calls[0][1][0]); + $args = $definition->getArguments(); + $this->assertEquals('doctrine_mongodb.odm.default_memcached_instance', (string) $args[0]); + $this->assertEquals('', $args[1]); $definition = $container->getDefinition('doctrine_mongodb.odm.default_memcached_instance'); $this->assertEquals('Memcached', $definition->getClass()); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 3c041d74..8036bfb7 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -183,7 +183,7 @@ public function testFullConfiguration(array $config): void 'persistent_collection_factory' => null, 'auto_mapping' => false, 'filters' => [], - 'metadata_cache_driver' => ['type' => 'apc'], + 'metadata_cache_driver' => ['type' => 'apcu'], 'mappings' => [ 'BarBundle' => [ 'type' => 'xml', diff --git a/Tests/DependencyInjection/Fixtures/config/xml/full.xml b/Tests/DependencyInjection/Fixtures/config/xml/full.xml index 939844be..893d4227 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/full.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/full.xml @@ -100,7 +100,7 @@ id="dm2" connection="dm2_connection" database="db1" - metadata-cache-driver="apc" + metadata-cache-driver="apcu" logging="true" repository-factory="doctrine_mongodb.odm.container_repository_factory" default-document-repository-class="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Repository\CustomRepository" diff --git a/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_multiple_connections.xml b/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_multiple_connections.xml index 4281734f..13b7b382 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_multiple_connections.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_multiple_connections.xml @@ -16,7 +16,7 @@ - - + + diff --git a/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml b/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml index bde73256..ce0ad039 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml @@ -11,7 +11,7 @@ - Doctrine\Common\Cache\MemcachedCache + Symfony\Component\Cache\Adapter\MemcachedAdapter localhost 11211 Memcached diff --git a/Tests/DependencyInjection/Fixtures/config/yml/full.yml b/Tests/DependencyInjection/Fixtures/config/yml/full.yml index 89538af7..d75ddc8b 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/full.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/full.yml @@ -105,5 +105,5 @@ doctrine_mongodb: prefix: prefix_val alias: alias_val is_bundle: false - metadata_cache_driver: apc + metadata_cache_driver: apcu logging: true diff --git a/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml b/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml index e4328140..16800e35 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml @@ -9,7 +9,7 @@ doctrine_mongodb: document_managers: dm1: connection: conn1 - metadata_cache_driver: xcache + metadata_cache_driver: array dm2: connection: conn2 - metadata_cache_driver: apc + metadata_cache_driver: apcu diff --git a/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml b/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml index b7b20dcf..d3bb827d 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml @@ -7,7 +7,7 @@ doctrine_mongodb: default: metadata_cache_driver: type: memcached - class: Doctrine\Common\Cache\MemcachedCache + class: Symfony\Component\Cache\Adapter\MemcachedAdapter host: localhost port: 11211 instance_class: Memcached diff --git a/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml b/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml index fb3ed665..f9a98d64 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml @@ -7,7 +7,7 @@ doctrine_mongodb: connection: default metadata_cache_driver: type: memcached - class: Doctrine\Common\Cache\MemcachedCache + class: Symfony\Component\Cache\Adapter\MemcachedAdapter host: localhost port: 11211 instance_class: Memcached From 55c41b757d2cb2e10d4c3baf3d0da9b2e1e04ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 19 Dec 2023 16:52:55 +0100 Subject: [PATCH 3/5] Update upgrade guide --- UPGRADE-5.0.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 8e259fe3..f5d8b861 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -13,8 +13,31 @@ UPGRADE FROM 4.x to 5.0 * All command and compiler pass classes are internal and final. They cannot be used directly or extended. * Remove support of Annotation mapping, you should use Attributes or XML instead. + +## Fixtures + * Remove `--service` option from `doctrine:mongodb:fixtures:load` command * Remove automatic injection of the container in fixtures classes implementing `ContainerAwareInterface`. You should use dependency injection instead. * Remove the `fixture_loader` configuration -* Metadata cache use a PSR-6 cache pool. Support for Doctrine Cache is dropped. + +## Cache + +The `Doctrine\Common\Cache\` providers are not supported anymore. The configuration +uses `Symfony\Component\Cache\Adapter\` providers instead, for PSR-6 compatibility. + +The recommended configuration for production is `doctrine_mongodb.system_cache_pool`: + +```yaml +when@prod: + doctrine_mongodb: + document_managers: + default: + metadata_cache_driver: + type: service + id: doctrine_mongodb.system_cache_pool +``` + +If you still want to use redis or memcached, the configuration of the host and port +must be done for each document manager. The parameters `doctrine_mongodb.odm.cache.memcached_*` +and `doctrine_mongodb.odm.cache.redis_*` are not read anymore. From ec7bad3838d63601f967637dee72a86bc83c7624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 19 Dec 2023 17:13:15 +0100 Subject: [PATCH 4/5] Remove useless new features --- .../DoctrineMongoDBExtension.php | 18 +++++------------- .../AbstractMongoDBExtensionTestCase.php | 1 - UPGRADE-5.0.md | 14 +------------- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index bba98479..cfb51067 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -581,7 +581,7 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName, case 'memcached': $memcachedClass = $cacheDriver['class'] ?? MemcachedAdapter::class; - $memcachedInstanceClass = $cacheDriver['instance_class'] ?? 'Memcache'; + $memcachedInstanceClass = $cacheDriver['instance_class'] ?? 'Memcached'; $memcachedHost = $cacheDriver['host'] ?? 'localhost'; $memcachedPort = $cacheDriver['port'] ?? '11211'; $memcachedInstance = new Definition($memcachedInstanceClass); @@ -591,10 +591,7 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName, ]); $container->setDefinition($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)), $memcachedInstance); - $cacheDef = new Definition($memcachedClass, [ - new Reference($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName))), - $cacheDriver['namespace'] ?? '', - ]); + $cacheDef = new Definition($memcachedClass, [new Reference($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)))]); break; @@ -610,22 +607,17 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName, ]); $container->setDefinition($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)), $redisInstance); - $cacheDef = new Definition($redisClass, [ - new Reference($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName))), - $cacheDriver['namespace'] ?? '', - ]); + $cacheDef = new Definition($redisClass, [new Reference($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)))]); break; case 'apcu': - $cacheDef = new Definition($cacheDriver['class'] ?? ApcuAdapter::class, [ - $cacheDriver['namespace'] ?? '', - ]); + $cacheDef = new Definition(ApcuAdapter::class); break; case 'array': - $cacheDef = new Definition($cacheDriver['class'] ?? ArrayAdapter::class); + $cacheDef = new Definition(ArrayAdapter::class); break; diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index 3a109702..a8cea00e 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -359,7 +359,6 @@ public function testDocumentManagerMemcachedMetadataCacheDriverConfiguration(): $args = $definition->getArguments(); $this->assertEquals('doctrine_mongodb.odm.default_memcached_instance', (string) $args[0]); - $this->assertEquals('', $args[1]); $definition = $container->getDefinition('doctrine_mongodb.odm.default_memcached_instance'); $this->assertEquals('Memcached', $definition->getClass()); diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index f5d8b861..6fb6fd95 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -26,18 +26,6 @@ UPGRADE FROM 4.x to 5.0 The `Doctrine\Common\Cache\` providers are not supported anymore. The configuration uses `Symfony\Component\Cache\Adapter\` providers instead, for PSR-6 compatibility. -The recommended configuration for production is `doctrine_mongodb.system_cache_pool`: - -```yaml -when@prod: - doctrine_mongodb: - document_managers: - default: - metadata_cache_driver: - type: service - id: doctrine_mongodb.system_cache_pool -``` - -If you still want to use redis or memcached, the configuration of the host and port +If you want to use redis or memcached, the configuration of `host`, `port` and `instance_class` must be done for each document manager. The parameters `doctrine_mongodb.odm.cache.memcached_*` and `doctrine_mongodb.odm.cache.redis_*` are not read anymore. From 4b4088fe0bb269008ad369aab9313aa5fae06e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 19 Dec 2023 19:28:39 +0100 Subject: [PATCH 5/5] Fix doc --- Resources/doc/config.rst | 16 ++++++++-------- .../AbstractMongoDBExtensionTestCase.php | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Resources/doc/config.rst b/Resources/doc/config.rst index cfc3aa01..0a81c71a 100644 --- a/Resources/doc/config.rst +++ b/Resources/doc/config.rst @@ -67,7 +67,7 @@ Sample Configuration server: '%env(resolve:MONGODB_URL)%' If you wish to use memcache to cache your metadata, you need to configure the -``Memcache`` instance; for example, you can do the following: +``Memcached`` instance; for example, you can do the following: .. configuration-block:: @@ -85,11 +85,11 @@ If you wish to use memcache to cache your metadata, you need to configure the mappings: AcmeDemoBundle: ~ metadata_cache_driver: - type: memcache + type: memcached class: Symfony\Component\Cache\Adapter\MemcachedAdapter host: localhost port: 11211 - instance_class: Memcache + instance_class: Memcached .. code-block:: xml @@ -104,11 +104,11 @@ If you wish to use memcache to cache your metadata, you need to configure the - - Doctrine\Common\Cache\MemcacheCache + + Symfony\Component\Cache\Adapter\MemcachedAdapter localhost 11211 - Memcache + Memcached @@ -330,7 +330,7 @@ following syntax: dm1: connection: conn1 database: db1 - metadata_cache_driver: xcache + metadata_cache_driver: array mappings: AcmeDemoBundle: ~ dm2: @@ -363,7 +363,7 @@ following syntax: - + diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index 440d78e1..29175548 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -15,6 +15,9 @@ use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; use MongoDB\Client; use PHPUnit\Framework\AssertionFailedError; +use Symfony\Component\Cache\Adapter\ApcuAdapter; +use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Cache\Adapter\MemcachedAdapter; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition;