Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Doctrine cache adapter for metadata #804

Merged
merged 6 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 0 additions & 100 deletions DependencyInjection/Compiler/CacheCompatibilityPass.php

This file was deleted.

30 changes: 11 additions & 19 deletions DependencyInjection/DoctrineMongoDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -582,40 +580,34 @@
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') . '%';
GromNaN marked this conversation as resolved.
Show resolved Hide resolved
$memcachedClass = $cacheDriver['class'] ?? MemcachedAdapter::class;
$memcachedInstanceClass = $cacheDriver['instance_class'] ?? 'Memcached';
$memcachedHost = $cacheDriver['host'] ?? 'localhost';
$memcachedPort = $cacheDriver['port'] ?? '11211';
$memcachedInstance = new Definition($memcachedInstanceClass);
$memcachedInstance->addMethodCall('addServer', [
$memcachedHost,
$memcachedPort,
]);
$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)))]);

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') . '%';
GromNaN marked this conversation as resolved.
Show resolved Hide resolved
$redisClass = $cacheDriver['class'] ?? RedisAdapter::class;
$redisInstanceClass = $cacheDriver['instance_class'] ?? 'Redis';
$redisHost = $cacheDriver['host'] ?? 'localhost';
$redisPort = $cacheDriver['port'] ?? '6379';

Check warning on line 602 in DependencyInjection/DoctrineMongoDBExtension.php

View check run for this annotation

Codecov / codecov/patch

DependencyInjection/DoctrineMongoDBExtension.php#L599-L602

Added lines #L599 - L602 were not covered by tests
$redisInstance = new Definition($redisInstanceClass);
$redisInstance->addMethodCall('connect', [
$redisHost,
$redisPort,
]);
$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)))]);

Check warning on line 610 in DependencyInjection/DoctrineMongoDBExtension.php

View check run for this annotation

Codecov / codecov/patch

DependencyInjection/DoctrineMongoDBExtension.php#L610

Added line #L610 was not covered by tests

break;

Expand All @@ -630,7 +622,7 @@
break;

default:
return parent::loadCacheDriver($cacheName, $objectManagerName, $cacheDriver, $container);
throw new InvalidArgumentException(sprintf('"%s" is an unrecognized cache driver.', $cacheDriver['type']));

Check warning on line 625 in DependencyInjection/DoctrineMongoDBExtension.php

View check run for this annotation

Codecov / codecov/patch

DependencyInjection/DoctrineMongoDBExtension.php#L625

Added line #L625 was not covered by tests
}

$cacheDef->setPublic(false);
Expand Down
2 changes: 0 additions & 2 deletions DoctrineMongoDBBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 0 additions & 14 deletions Resources/config/mongodb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@
<parameter key="doctrine_mongodb.odm.hydrator_cache_warmer.class">Doctrine\Bundle\MongoDBBundle\CacheWarmer\HydratorCacheWarmer</parameter>
<parameter key="doctrine_mongodb.odm.persistent_collection_cache_warmer.class">Doctrine\Bundle\MongoDBBundle\CacheWarmer\PersistentCollectionCacheWarmer</parameter>

<!-- cache -->
<parameter key="doctrine_mongodb.odm.cache.array.class">Doctrine\Common\Cache\ArrayCache</parameter>
<parameter key="doctrine_mongodb.odm.cache.apc.class">Doctrine\Common\Cache\ApcCache</parameter>
<parameter key="doctrine_mongodb.odm.cache.apcu.class">Doctrine\Common\Cache\ApcuCache</parameter>
<parameter key="doctrine_mongodb.odm.cache.memcache.class">Doctrine\Common\Cache\MemcacheCache</parameter>
<parameter key="doctrine_mongodb.odm.cache.memcache_host">localhost</parameter>
<parameter key="doctrine_mongodb.odm.cache.memcache_port">11211</parameter>
<parameter key="doctrine_mongodb.odm.cache.memcache_instance.class">Memcache</parameter>
<parameter key="doctrine_mongodb.odm.cache.xcache.class">Doctrine\Common\Cache\XcacheCache</parameter>

<!-- metadata -->
<parameter key="doctrine_mongodb.odm.metadata.driver_chain.class">Doctrine\Persistence\Mapping\Driver\MappingDriverChain</parameter>
<parameter key="doctrine_mongodb.odm.metadata.attribute.class">Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver</parameter>
Expand All @@ -49,7 +39,6 @@

<services>
<!-- defaults -->
<service id="doctrine_mongodb.odm.cache" alias="doctrine_mongodb.odm.cache.array" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be deprecated in 4.7. This is not used.

<service id="%doctrine_mongodb.odm.document_manager.class%" alias="doctrine_mongodb.odm.document_manager" public="false" />
<service id="%doctrine_mongodb.odm.class%" alias="doctrine_mongodb" public="false" />

Expand Down Expand Up @@ -113,9 +102,6 @@
<argument type="collection" />
</service>

<!-- cache -->
<service id="doctrine_mongodb.odm.cache.array" class="%doctrine_mongodb.odm.cache.array.class%" />

<!-- logger -->
<service id="doctrine_mongodb.odm.command_logger_registry" class="Doctrine\Bundle\MongoDBBundle\APM\CommandLoggerRegistry" public="true">
<argument type="tagged" tag="doctrine_mongodb.odm.command_logger" />
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
31 changes: 8 additions & 23 deletions Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));

Expand Down Expand Up @@ -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 */
Expand All @@ -369,11 +355,10 @@ 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]);

$definition = $container->getDefinition('doctrine_mongodb.odm.default_memcached_instance');
$this->assertEquals('Memcached', $definition->getClass());
Expand Down
Loading