1111
1212namespace Cache \CacheBundle \DependencyInjection \Compiler ;
1313
14- use Cache \Bridge \DoctrineCacheBridge ;
1514use Cache \CacheBundle \Cache \FixedTaggingCachePool ;
15+ use Cache \CacheBundle \Factory \DoctrineBridgeFactory ;
1616use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
1717use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
1818use Symfony \Component \DependencyInjection \ContainerBuilder ;
2424 * @author Aaron Scherer <aequasi@gmail.com>
2525 * @author Tobias Nyholm <tobias.nyholm@gmail.com>
2626 */
27- class DoctrineSupportCompilerPass implements CompilerPassInterface
27+ class DoctrineCompilerPass implements CompilerPassInterface
2828{
2929 /**
3030 * @type ContainerBuilder
@@ -51,12 +51,6 @@ public function process(ContainerBuilder $container)
5151 );
5252 }
5353
54- if (!class_exists ('Cache\Bridge\DoctrineCacheBridge ' )) {
55- throw new \Exception (
56- 'You need the DoctrineBridge to be able to cache queries, results and metadata. Please run "composer require cache/psr-6-doctrine-bridge" to install the missing dependency. '
57- );
58- }
59-
6054 $ this ->enableDoctrineSupport ($ this ->container ->getParameter ('cache.doctrine ' ));
6155 }
6256
@@ -70,19 +64,23 @@ public function process(ContainerBuilder $container)
7064 protected function enableDoctrineSupport (array $ config )
7165 {
7266 $ types = ['entity_managers ' , 'document_managers ' ];
73- foreach ($ config as $ cacheType => $ cacheData ) {
67+ // For each ['metadata' => [], 'result' => [], 'query' => []]
68+ foreach ($ config as $ cacheType => $ typeConfig ) {
7469 foreach ($ types as $ type ) {
75- if (!isset ($ cacheData [$ type ])) {
70+ if (!isset ($ typeConfig [$ type ])) {
7671 continue ;
7772 }
7873
7974 // Doctrine can't talk to a PSR-6 cache, so we need a bridge
80- $ bridgeServiceId = sprintf ('cache.provider.doctrine.%s.bridge ' , $ cacheType );
81- $ bridgeDef = $ this ->container ->register ($ bridgeServiceId , DoctrineCacheBridge::class);
82- $ bridgeDef ->addArgument (new Reference ($ this ->getPoolReferenceForBridge ($ bridgeServiceId , $ cacheData , $ config ['use_tagging ' ])))
83- ->setPublic (false );
84-
85- foreach ($ cacheData [$ type ] as $ manager ) {
75+ $ bridgeServiceId = sprintf ('cache.service.doctrine.%s.%s.bridge ' , $ cacheType , $ type );
76+ $ this ->container ->register ($ bridgeServiceId , FixedTaggingCachePool::class)
77+ ->setPublic (false )
78+ ->setFactory ([DoctrineBridgeFactory::class, 'get ' ])
79+ ->addArgument (new Reference ($ typeConfig ['service_id ' ]))
80+ ->addArgument ($ typeConfig )
81+ ->addArgument (['doctrine ' , $ cacheType ]);
82+
83+ foreach ($ typeConfig [$ type ] as $ manager ) {
8684 $ doctrineDefinitionId =
8785 sprintf (
8886 'doctrine.%s.%s_%s_cache ' ,
@@ -98,31 +96,6 @@ protected function enableDoctrineSupport(array $config)
9896 }
9997 }
10098
101- /**
102- * Get a reference string for the PSR-6 cache implementation service to use with doctrine.
103- * If we support tagging we use the DoctrineTaggingCachePool.
104- *
105- * @param string $bridgeServiceId
106- * @param array $cacheData
107- * @param bool $tagging
108- *
109- * @return string
110- */
111- public function getPoolReferenceForBridge ($ bridgeServiceId , $ cacheData , $ tagging )
112- {
113- if (!$ tagging ) {
114- return $ cacheData ['service_id ' ];
115- }
116-
117- $ taggingServiceId = $ bridgeServiceId .'.tagging ' ;
118- $ taggingDef = $ this ->container ->register ($ taggingServiceId , FixedTaggingCachePool::class);
119- $ taggingDef ->addArgument (new Reference ($ cacheData ['service_id ' ]))
120- ->addArgument (['doctrine ' ])
121- ->setPublic (false );
122-
123- return $ taggingServiceId ;
124- }
125-
12699 /**
127100 * Checks to see if there are ORM's or ODM's.
128101 *
0 commit comments