Skip to content

Commit 3c5c4b6

Browse files
committed
Moving LoggingCachePool to compiler pass
1 parent c04df6f commit 3c5c4b6

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/DependencyInjection/CacheExtension.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public function load(array $configs, ContainerBuilder $container)
3535
$config = $this->processConfiguration(new Configuration(), $configs);
3636

3737
if ($container->getParameter('kernel.debug')) {
38-
$this->transformLoggableCachePools($container);
39-
4038
$container->register('data_collector.cache', CacheDataCollector::class)
4139
->addTag('data_collector', ['template' => CacheDataCollector::TEMPLATE, 'id' => 'cache']);
4240
}
@@ -53,16 +51,4 @@ public function getAlias()
5351
{
5452
return 'cache';
5553
}
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-
}
6854
}

src/DependencyInjection/Compiler/DataCollectorCompilerPass.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class DataCollectorCompilerPass extends BaseCompilerPass
2525
*/
2626
protected function prepare()
2727
{
28+
$this->transformLoggableCachePools();
29+
2830
$instances = $this->container->getParameter($this->getAlias() . '.instance');
2931

3032
$definition = $this->container->getDefinition('data_collector.cache');
@@ -36,4 +38,21 @@ protected function prepare()
3638

3739
$this->container->setDefinition('data_collector.cache', $definition);
3840
}
41+
42+
private function transformLoggableCachePools()
43+
{
44+
$serviceIds = $this->container->findTaggedServiceIds('cache.provider');
45+
foreach (array_keys($serviceIds) as $id) {
46+
47+
// Duplicating definition to $originalServiceId.logged
48+
$this->container->setDefinition($id.'.logged', $this->container->findDefinition($id));
49+
50+
// Creating a LoggingCachePool instance, and passing it the new definition from above
51+
$def = $this->container->register($id.'.logger', LoggingCachePool::class);
52+
$def->addArgument(new Reference($id.'.logged'));
53+
54+
// Overwrite the original service id with the new LoggingCachePool instance
55+
$this->container->setAlias($id, $id.'.logger');
56+
}
57+
}
3958
}

0 commit comments

Comments
 (0)