1313
1414use Cache \Bridge \DoctrineCacheBridge ;
1515use Cache \CacheBundle \Cache \FixedTaggingCachePool ;
16+ use Cache \CacheBundle \Factory \DoctrineBridgeFactory ;
1617use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
1718use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
1819use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -70,19 +71,23 @@ public function process(ContainerBuilder $container)
7071 protected function enableDoctrineSupport (array $ config )
7172 {
7273 $ types = ['entity_managers ' , 'document_managers ' ];
73- foreach ($ config as $ cacheType => $ cacheData ) {
74+ // For each ['metadata' => [], 'result' => [], 'query' => []]
75+ foreach ($ config as $ cacheType => $ typeConfig ) {
7476 foreach ($ types as $ type ) {
75- if (!isset ($ cacheData [$ type ])) {
77+ if (!isset ($ typeConfig [$ type ])) {
7678 continue ;
7779 }
7880
7981 // 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 ) {
82+ $ bridgeServiceId = sprintf ('cache.service.doctrine.%s.%s.bridge ' , $ cacheType , $ type );
83+ $ this ->container ->register ($ bridgeServiceId , FixedTaggingCachePool::class)
84+ ->setPublic (false )
85+ ->setFactory ([DoctrineBridgeFactory::class, 'get ' ])
86+ ->addArgument (new Reference ($ typeConfig ['service_id ' ]))
87+ ->addArgument ($ typeConfig )
88+ ->addArgument (['doctrine ' , $ cacheType ]);
89+
90+ foreach ($ typeConfig [$ type ] as $ manager ) {
8691 $ doctrineDefinitionId =
8792 sprintf (
8893 'doctrine.%s.%s_%s_cache ' ,
@@ -98,31 +103,6 @@ protected function enableDoctrineSupport(array $config)
98103 }
99104 }
100105
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-
126106 /**
127107 * Checks to see if there are ORM's or ODM's.
128108 *
0 commit comments