From 386225fa3e45a7418b4eb0db50fee8a3372ceab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Tue, 10 Nov 2020 21:03:46 +0100 Subject: [PATCH] Revert "Add PhpArrayAdapter to cache metadata" --- CacheWarmer/DoctrineMetadataCacheWarmer.php | 35 ----------- DependencyInjection/Configuration.php | 7 --- DependencyInjection/DoctrineExtension.php | 30 --------- .../DoctrineExtensionTest.php | 62 +++++-------------- UPGRADE-2.2.md | 1 - 5 files changed, 16 insertions(+), 119 deletions(-) delete mode 100644 CacheWarmer/DoctrineMetadataCacheWarmer.php diff --git a/CacheWarmer/DoctrineMetadataCacheWarmer.php b/CacheWarmer/DoctrineMetadataCacheWarmer.php deleted file mode 100644 index 81585b4ef..000000000 --- a/CacheWarmer/DoctrineMetadataCacheWarmer.php +++ /dev/null @@ -1,35 +0,0 @@ -entityManager = $entityManager; - - parent::__construct($phpArrayFile); - } - - /** - * @param string $cacheDir - */ - protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter): bool - { - $metadataFactory = new ClassMetadataFactory(); - $metadataFactory->setEntityManager($this->entityManager); - $metadataFactory->setCacheDriver(new DoctrineProvider($arrayAdapter)); - $metadataFactory->getAllMetadata(); - - return true; - } -} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f5c5c79b1..00fd91518 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -688,13 +688,6 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition ->scalarNode('pool')->end() ->end(); - if ($name === 'metadata_cache_driver') { - $node->setDeprecated(...$this->getDeprecationMsg( - 'The "metadata_cache_driver" configuration key is deprecated. PHP Array cache is now automatically registered when %kernel.debug% is false.', - '2.2' - )); - } - return $node; } diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index bd05a6e43..163caddd6 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -2,7 +2,6 @@ namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection; -use Doctrine\Bundle\DoctrineBundle\CacheWarmer\DoctrineMetadataCacheWarmer; use Doctrine\Bundle\DoctrineBundle\Dbal\ManagerRegistryAwareConnectionProvider; use Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; @@ -22,8 +21,6 @@ use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber; use Symfony\Bridge\Doctrine\Validator\DoctrineLoader; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\DoctrineAdapter; -use Symfony\Component\Cache\Adapter\PhpArrayAdapter; use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; @@ -816,12 +813,6 @@ protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $c $this->loadCacheDriver('metadata_cache', $entityManager['name'], $entityManager['metadata_cache_driver'], $container); $this->loadCacheDriver('result_cache', $entityManager['name'], $entityManager['result_cache_driver'], $container); $this->loadCacheDriver('query_cache', $entityManager['name'], $entityManager['query_cache_driver'], $container); - - if ($container->getParameter('kernel.debug')) { - return; - } - - $this->registerMetadataPhpArrayCaching($entityManager['name'], $container); } /** @@ -935,25 +926,4 @@ private function createArrayAdapterCachePool(ContainerBuilder $container, string return $id; } - - private function registerMetadataPhpArrayCaching(string $entityManagerName, ContainerBuilder $container): void - { - $metadataCacheAlias = $this->getObjectManagerElementName($entityManagerName . '_metadata_cache'); - $decoratedMetadataCacheServiceId = (string) $container->getAlias($metadataCacheAlias); - $phpArrayCacheDecoratorServiceId = $decoratedMetadataCacheServiceId . '.php_array'; - $phpArrayFile = '%kernel.cache_dir%' . sprintf('/doctrine/orm/%s_metadata.php', $entityManagerName); - - $container->register(DoctrineMetadataCacheWarmer::class) - ->setArguments([new Reference(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName)), $phpArrayFile]) - ->addTag('kernel.cache_warmer'); - - $container->setAlias($metadataCacheAlias, $phpArrayCacheDecoratorServiceId); - $container->register($phpArrayCacheDecoratorServiceId, DoctrineProvider::class) - ->addArgument( - new Definition(PhpArrayAdapter::class, [ - $phpArrayFile, - new Definition(DoctrineAdapter::class, [new Reference($decoratedMetadataCacheServiceId)]), - ]) - ); - } } diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index b0ef02dd1..a0e568e8f 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -12,8 +12,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\DoctrineAdapter; -use Symfony\Component\Cache\Adapter\PhpArrayAdapter; use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -349,18 +347,6 @@ public function testDependencyInjectionConfigurationDefaults(): void $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); $this->assertEquals(DoctrineProvider::class, $definition->getClass()); $arguments = $definition->getArguments(); - $this->assertInstanceOf(Definition::class, $arguments[0]); - $this->assertEquals(PhpArrayAdapter::class, $arguments[0]->getClass()); - $arguments = $arguments[0]->getArguments(); - $this->assertSame('%kernel.cache_dir%/doctrine/orm/default_metadata.php', $arguments[0]); - $this->assertInstanceOf(Definition::class, $arguments[1]); - $this->assertEquals(DoctrineAdapter::class, $arguments[1]->getClass()); - $arguments = $arguments[1]->getArguments(); - $this->assertInstanceOf(Reference::class, $arguments[0]); - $this->assertEquals('doctrine.orm.cache.provider.cache.doctrine.orm.default.metadata', (string) $arguments[0]); - $definition = $container->getDefinition((string) $arguments[0]); - $this->assertEquals(DoctrineProvider::class, $definition->getClass()); - $arguments = $definition->getArguments(); $this->assertInstanceOf(Reference::class, $arguments[0]); $this->assertEquals('cache.doctrine.orm.default.metadata', (string) $arguments[0]); $this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass()); @@ -766,9 +752,6 @@ public function testMessengerIntegration(): void } } - /** - * @group legacy - */ public function testInvalidCacheConfiguration(): void { if (! interface_exists(EntityManagerInterface::class)) { @@ -815,42 +798,15 @@ public function testCacheConfiguration(string $expectedAliasName, string $expect $this->assertEquals($expectedAliasTarget, (string) $alias); } - /** - * @dataProvider legacyCacheConfigurationProvider - * @group legacy - */ - public function testLegacyCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, array $cacheConfig): void - { - $this->testCacheConfiguration($expectedAliasName, $expectedAliasTarget, $cacheName, $cacheConfig); - } - - public static function legacyCacheConfigurationProvider(): array + public static function cacheConfigurationProvider(): array { return [ 'metadata_cache_default' => [ 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.metadata.php_array', + 'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.metadata', 'cacheName' => 'metadata_cache_driver', 'cacheConfig' => ['type' => null], ], - 'metadata_cache_pool' => [ - 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.metadata_cache_pool.php_array', - 'cacheName' => 'metadata_cache_driver', - 'cacheConfig' => ['type' => 'pool', 'pool' => 'metadata_cache_pool'], - ], - 'metadata_cache_service' => [ - 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', - 'expectedAliasTarget' => 'service_target_metadata.php_array', - 'cacheName' => 'metadata_cache_driver', - 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata'], - ], - ]; - } - - public static function cacheConfigurationProvider(): array - { - return [ 'query_cache_default' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', 'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.query', @@ -863,6 +819,13 @@ public static function cacheConfigurationProvider(): array 'cacheName' => 'result_cache_driver', 'cacheConfig' => ['type' => null], ], + + 'metadata_cache_pool' => [ + 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', + 'expectedAliasTarget' => 'doctrine.orm.cache.provider.metadata_cache_pool', + 'cacheName' => 'metadata_cache_driver', + 'cacheConfig' => ['type' => 'pool', 'pool' => 'metadata_cache_pool'], + ], 'query_cache_pool' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', 'expectedAliasTarget' => 'doctrine.orm.cache.provider.query_cache_pool', @@ -875,6 +838,13 @@ public static function cacheConfigurationProvider(): array 'cacheName' => 'result_cache_driver', 'cacheConfig' => ['type' => 'pool', 'pool' => 'result_cache_pool'], ], + + 'metadata_cache_service' => [ + 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', + 'expectedAliasTarget' => 'service_target_metadata', + 'cacheName' => 'metadata_cache_driver', + 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata'], + ], 'query_cache_service' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', 'expectedAliasTarget' => 'service_target_query', diff --git a/UPGRADE-2.2.md b/UPGRADE-2.2.md index eaf6f5eaa..caa96166d 100644 --- a/UPGRADE-2.2.md +++ b/UPGRADE-2.2.md @@ -13,4 +13,3 @@ Configuration * `doctrine.dbal.keep_slave`. Use `doctrine.dbal.keep_replica` Similarly, if you use XML configuration, please replace `` with ``. - * The `metadata_cache_driver` configuration key has been deprecated. PHP Array cache is now automatically registered when `%kernel.debug%` is false.