diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9b7c55cc2..18ce588b2 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -706,16 +706,16 @@ private function getOrmCacheDriverNode($name) }) ->end() ->children() - ->scalarNode('type')->defaultValue('array')->end() + ->scalarNode('type')->defaultNull()->end() ->scalarNode('id')->end() ->scalarNode('pool')->end() - ->scalarNode('host')->end() - ->scalarNode('port')->end() - ->scalarNode('database')->end() - ->scalarNode('instance_class')->end() - ->scalarNode('class')->end() - ->scalarNode('namespace')->defaultNull()->end() - ->scalarNode('cache_provider')->defaultNull()->end() + ->scalarNode('host')->setDeprecated()->end() + ->scalarNode('port')->setDeprecated()->end() + ->scalarNode('database')->setDeprecated()->end() + ->scalarNode('instance_class')->setDeprecated()->end() + ->scalarNode('class')->setDeprecated()->end() + ->scalarNode('namespace')->defaultNull()->setDeprecated()->end() + ->scalarNode('cache_provider')->defaultNull()->setDeprecated()->end() ->end(); return $node; diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index daea1d7c7..545a66523 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -29,8 +29,10 @@ use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; +use const E_USER_DEPRECATED; use function class_exists; use function sprintf; +use function trigger_error; /** * DoctrineExtension is an extension for the Doctrine DBAL and ORM library. @@ -739,13 +741,24 @@ protected function loadCacheDriver($driverName, $entityManagerName, array $drive $serviceId = null; $aliasId = $this->getObjectManagerElementName(sprintf('%s_%s', $entityManagerName, $driverName)); + if ($driverMap['type'] === null) { + $driverMap = [ + 'type' => 'pool', + 'pool' => $this->getPoolNameForCacheDriver($driverName), + ]; + } + + $usesDeprecatedCacheType = true; + switch ($driverMap['type']) { case 'service': - $serviceId = $driverMap['id']; + $usesDeprecatedCacheType = false; + $serviceId = $driverMap['id']; break; case 'pool': - $serviceId = $this->createPoolCacheDefinition($container, $driverMap['pool']); + $usesDeprecatedCacheType = false; + $serviceId = $this->createPoolCacheDefinition($container, $driverMap['pool']); break; case 'provider': @@ -753,6 +766,17 @@ protected function loadCacheDriver($driverName, $entityManagerName, array $drive break; } + if ($usesDeprecatedCacheType) { + @trigger_error( + sprintf( + 'Using the "%s" type for cache "%s" is deprecated since DoctrineBundle 1.12 and will be dropped in 2.0. Please use the "id" or "pool" types exclusively.', + $driverMap['type'], + $driverName + ), + E_USER_DEPRECATED + ); + } + if ($serviceId !== null) { $container->setAlias($aliasId, new Alias($serviceId, false)); @@ -888,4 +912,14 @@ private function createPoolCacheDefinition(ContainerBuilder $container, string $ return $serviceId; } + + private function getPoolNameForCacheDriver(string $driverName) : string + { + switch ($driverName) { + case 'metadata_cache': + return 'cache.system'; + default: + return 'cache.app'; + } + } } diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index db669f687..161a5c580 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests; use Doctrine\Common\Annotations\Reader; -use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\EventManager; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; @@ -20,6 +19,7 @@ use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator; use Symfony\Bridge\Doctrine\Validator\DoctrineLoader; +use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; class ContainerTest extends TestCase @@ -47,9 +47,9 @@ public function testContainer() $this->assertInstanceOf(Reader::class, $container->get('doctrine.orm.metadata.annotation_reader')); $this->assertInstanceOf(Configuration::class, $container->get('doctrine.orm.default_configuration')); $this->assertInstanceOf(MappingDriverChain::class, $container->get('doctrine.orm.default_metadata_driver')); - $this->assertInstanceOf(ArrayCache::class, $container->get('doctrine.orm.default_metadata_cache')); - $this->assertInstanceOf(ArrayCache::class, $container->get('doctrine.orm.default_query_cache')); - $this->assertInstanceOf(ArrayCache::class, $container->get('doctrine.orm.default_result_cache')); + $this->assertInstanceOf(DoctrineProvider::class, $container->get('doctrine.orm.default_metadata_cache')); + $this->assertInstanceOf(DoctrineProvider::class, $container->get('doctrine.orm.default_query_cache')); + $this->assertInstanceOf(DoctrineProvider::class, $container->get('doctrine.orm.default_result_cache')); $this->assertInstanceOf(EntityManager::class, $container->get('doctrine.orm.default_entity_manager')); $this->assertInstanceOf(Connection::class, $container->get('database_connection')); $this->assertInstanceOf(EntityManager::class, $container->get('doctrine.orm.entity_manager')); diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index aac21d889..69f116d31 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -10,6 +10,8 @@ use Doctrine\ORM\EntityManager; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; +use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -188,6 +190,9 @@ public function testDbalLoadSavepointsForNestedTransactions() $this->assertCount(0, $calls); } + /** + * @group legacy + */ public function testLoadSimpleSingleConnection() { $container = $this->loadContainer('orm_service_simple_single_entity_manager'); @@ -222,6 +227,8 @@ public function testLoadSimpleSingleConnection() /** * The PDO driver doesn't require a database name to be to set when connecting to a database server + * + * @group legacy */ public function testLoadSimpleSingleConnectionWithoutDbName() { @@ -258,6 +265,9 @@ public function testLoadSimpleSingleConnectionWithoutDbName() ]); } + /** + * @group legacy + */ public function testLoadSingleConnection() { $container = $this->loadContainer('orm_service_single_entity_manager'); @@ -294,6 +304,9 @@ public function testLoadSingleConnection() $this->assertDICDefinitionMethodCallOnce($configDef, 'setDefaultRepositoryClassName', ['Acme\Doctrine\Repository']); } + /** + * @group legacy + */ public function testLoadMultipleConnections() { $container = $this->loadContainer('orm_service_multiple_entity_managers'); @@ -342,10 +355,16 @@ public function testLoadMultipleConnections() $this->assertEquals('%doctrine_cache.xcache.class%', $definition->getClass()); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_query_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_result_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); } public function testLoadLogging() @@ -368,6 +387,9 @@ public function testLoadLogging() $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', [new Reference('doctrine.dbal.logger.chain.both')]); } + /** + * @group legacy + */ public function testEntityManagerMetadataCacheDriverConfiguration() { $container = $this->loadContainer('orm_service_multiple_entity_managers'); @@ -379,6 +401,9 @@ public function testEntityManagerMetadataCacheDriverConfiguration() $this->assertDICDefinitionClass($definition, '%doctrine_cache.apc.class%'); } + /** + * @group legacy + */ public function testEntityManagerMemcacheMetadataCacheDriverConfiguration() { $container = $this->loadContainer('orm_service_simple_single_entity_manager'); @@ -399,6 +424,9 @@ public function testEntityManagerMemcacheMetadataCacheDriverConfiguration() ]); } + /** + * @group legacy + */ public function testEntityManagerRedisMetadataCacheDriverConfigurationWithDatabaseKey() { $container = $this->loadContainer('orm_service_simple_single_entity_manager_redis'); @@ -417,6 +445,9 @@ public function testEntityManagerRedisMetadataCacheDriverConfigurationWithDataba $this->assertDICDefinitionMethodCallOnce($definition, 'select', [1]); } + /** + * @group legacy + */ public function testDependencyInjectionImportsOverrideDefaults() { $container = $this->loadContainer('orm_imports'); @@ -570,6 +601,9 @@ public function testSetQuoteStrategy() $this->assertDICDefinitionMethodCallOnce($def2, 'setQuoteStrategy', [0 => new Reference('doctrine.orm.quote_strategy.ansi')]); } + /** + * @group legacy + */ public function testSecondLevelCache() { $container = $this->loadContainer('orm_second_level_cache'); @@ -990,6 +1024,10 @@ public function testRepositoryFactory() private function loadContainer($fixture, array $bundles = ['YamlBundle'], CompilerPassInterface $compilerPass = null) { $container = $this->getContainer($bundles); + $extension = new FrameworkExtension(); + $container->registerExtension($extension); + $extension->load(['framework' => []], $container); + $container->registerExtension(new DoctrineExtension()); $this->loadFromFile($container, $fixture); @@ -1019,6 +1057,9 @@ private function getContainer(array $bundles) 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . '/../../', // src dir + 'kernel.project_dir' => __DIR__ . '/../../', // src dir + 'kernel.bundles_metadata' => [], + 'container.build_id' => uniqid(), ])); } diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index edd415107..aadb8e00e 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; +use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -320,13 +321,22 @@ public function testDependencyInjectionConfigurationDefaults() $this->assertEquals('doctrine.orm.default_entity_listener_resolver', (string) $calls[12][1][0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.system', (string) $arguments[0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_query_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_result_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); } public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection() @@ -393,6 +403,9 @@ public function testSingleEntityManagerWithDefaultConfiguration() ]); } + /** + * @group legacy + */ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration() { $container = $this->getContainer(); @@ -418,6 +431,9 @@ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration( $this->assertEquals('%doctrine.orm.second_level_cache.default_cache_factory.class%', $slcDefinition->getClass()); } + /** + * @group legacy + */ public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() { $container = $this->getContainer(); @@ -674,6 +690,7 @@ public function testMessengerIntegration() /** * @param array|string $cacheConfig * + * @group legacy * @dataProvider cacheConfigurationProvider */ public function testCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, $cacheConfig) : void diff --git a/Tests/ServiceRepositoryTest.php b/Tests/ServiceRepositoryTest.php index 21754f707..f711e5cca 100644 --- a/Tests/ServiceRepositoryTest.php +++ b/Tests/ServiceRepositoryTest.php @@ -15,6 +15,7 @@ use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository; use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoRepository; use Fixtures\Bundles\RepositoryServiceBundle\RepositoryServiceBundle; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -44,8 +45,19 @@ public function testRepositoryServiceWiring() 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.bundles_metadata' => [], + 'kernel.charset' => 'UTF-8', + 'kernel.container_class' => ContainerBuilder::class, + 'kernel.secret' => 'test', + 'container.build_id' => uniqid(), ])); $container->set('annotation_reader', new AnnotationReader()); + + $extension = new FrameworkExtension(); + $container->registerExtension($extension); + $extension->load(['framework' => []], $container); + $extension = new DoctrineExtension(); $container->registerExtension($extension); $extension->load([[ diff --git a/Tests/TestCase.php b/Tests/TestCase.php index d57c94652..79cbafb43 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -7,6 +7,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\ORM\Version; use PHPUnit\Framework\TestCase as BaseTestCase; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -33,8 +34,16 @@ public function createYamlBundleTestContainer() 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.bundles_metadata' => [], + 'container.build_id' => uniqid(), ])); $container->set('annotation_reader', new AnnotationReader()); + + $extension = new FrameworkExtension(); + $container->registerExtension($extension); + $extension->load(['framework' => []], $container); + $extension = new DoctrineExtension(); $container->registerExtension($extension); $extension->load([[ diff --git a/UPGRADE-1.12.md b/UPGRADE-1.12.md new file mode 100644 index 000000000..2ed54db24 --- /dev/null +++ b/UPGRADE-1.12.md @@ -0,0 +1,11 @@ +UPGRADE FROM 1.11 to 1.12 +========================= + +Deprecation of DoctrineCacheBundle +---------------------------------- + +With DoctrineCacheBundle [being deprecated](https://github.com/doctrine/DoctrineCacheBundle/issues/156), +configuring caches through it has been deprecated. If you are using anything +other than the `pool` or `id` cache types, please update your configuration to +either use symfony/cache through the `pool` type or configure your cache +services manually and use the `service` type. diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index f5ad6ea49..6567b1424 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -20,6 +20,13 @@ Commands * `Doctrine\Bundle\DoctrineBundle\Command` no longer implements `ContainerAwareInterface`. +Deprecation of DoctrineCacheBundle +---------------------------------- + +Configuring caches through DoctrineCacheBundle is no longer possible. Please use +symfony/cache through the `pool` type or configure your cache services manually +and use the `service` type. + Mapping ------- diff --git a/composer.json b/composer.json index 806a6d547..83876e286 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "require-dev": { "doctrine/orm": "^2.6", "symfony/cache": "^3.4|^4.1", + "symfony/translation": "^3.4|^4.1", "symfony/yaml": "^3.4|^4.1", "symfony/validator": "^3.4|^4.1", "symfony/property-info": "^3.4|^4.1",