Skip to content

Commit

Permalink
Avoid using deprecated methods
Browse files Browse the repository at this point in the history
MongoDB ODM 2.2 deprecated `Doctrine\ODM\MongoDB\Configuration::getMetadataCacheImpl()` and `Doctrine\ODM\MongoDB\Configuration::setMetadataCacheImpl()` in favor of Configuration::getMetadataCache and `Configuration::setMetadataCache()`, respectively which use a PSR-6 compliant cache instead of doctrine/cache.

I refrained from allowing to pass a PSR-6 `CacheItemPoolInterface` directly for now, because it's currently unlikely that a cache pulled from `doctrine.cache.[name]` service key will return a PSR-6 cache. Such a change would probably also require changes in doctrine-module and doctrine-orm-module.
If you want me to implement that forward compatibility layer right away it's also ok for me.

Signed-off-by: Thomas Rieschl <thomas@trinet.at>
  • Loading branch information
rieschl committed Sep 12, 2023
1 parent 2f0c146 commit 08ddd2f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Service/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DoctrineMongoODMModule\Service;

use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\Types\Type;
use DoctrineMongoODMModule\Options;
Expand Down Expand Up @@ -68,7 +69,8 @@ public function __invoke(ContainerInterface $container, $requestedName, array|nu
}

// caching
$config->setMetadataCacheImpl($container->get($configurationOptions->getMetadataCache()));
$cache = $container->get($configurationOptions->getMetadataCache());
$config->setMetadataCache(CacheAdapter::wrap($cache));

// Register filters
foreach ($configurationOptions->getFilters() as $alias => $class) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace DoctrineMongoODMModuleTest\Doctrine;

use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\ODM\MongoDB\APM\CommandLoggerInterface;
use Doctrine\ODM\MongoDB\Configuration as Config;
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionFactory;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function testCreation(): void

$this->assertInstanceOf(Config::class, $config);

$this->assertSame($metadataCache, $config->getMetadataCacheImpl());
$this->assertEquals(CacheAdapter::wrap($metadataCache), $config->getMetadataCache());
$this->assertSame($mappingDriver, $config->getMetadataDriverImpl());

$this->assertSame(Config::AUTOGENERATE_EVAL, $config->getAutoGenerateProxyClasses());
Expand Down

0 comments on commit 08ddd2f

Please sign in to comment.