1111
1212namespace Cache \CacheBundle \DependencyInjection ;
1313
14+ use Cache \CacheBundle \Cache \LoggingCachePool ;
1415use Cache \CacheBundle \DataCollector \CacheDataCollector ;
1516use Symfony \Component \DependencyInjection \ContainerBuilder ;
17+ use Symfony \Component \DependencyInjection \Reference ;
1618use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
1719
1820/**
@@ -33,6 +35,8 @@ public function load(array $configs, ContainerBuilder $container)
3335 $ config = $ this ->processConfiguration (new Configuration (), $ configs );
3436
3537 if ($ container ->getParameter ('kernel.debug ' )) {
38+ $ this ->transformLoggableCachePools ($ container );
39+
3640 $ container ->register ('data_collector.cache ' , CacheDataCollector::class)
3741 ->addTag ('data_collector ' , ['template ' => CacheDataCollector::TEMPLATE , 'id ' => 'cache ' ]);
3842 }
@@ -42,10 +46,23 @@ public function load(array $configs, ContainerBuilder $container)
4246 $ container ->setParameter ($ this ->getAlias ().'. ' .$ section , $ config [$ section ]);
4347 }
4448 }
49+
4550 }
4651
4752 public function getAlias ()
4853 {
4954 return 'cache ' ;
5055 }
56+
57+ private function transformLoggableCachePools (ContainerBuilder $ container )
58+ {
59+ $ serviceIds = $ container ->findTaggedServiceIds ('cache.provider ' );
60+ foreach (array_keys ($ serviceIds ) as $ id ) {
61+ $ container ->setDefinition ($ id .'.logged ' , $ container ->findDefinition ($ id ));
62+ $ def = $ container ->register ($ id .'.logger ' , LoggingCachePool::class);
63+ $ def ->addArgument (new Reference ($ id ));
64+
65+ $ container ->setAlias ($ id , $ id .'.logger ' );
66+ }
67+ }
5168}
0 commit comments