Skip to content

Commit c111060

Browse files
committed
Tag all cache services with "cache.provider"
1 parent 1bc901a commit c111060

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/CacheBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function build(ContainerBuilder $container)
2929
{
3030
parent::build($container);
3131

32+
$container->addCompilerPass(new Compiler\CacheTaggingPass());
3233
$container->addCompilerPass(new Compiler\SessionSupportCompilerPass());
3334
$container->addCompilerPass(new Compiler\DoctrineSupportCompilerPass());
3435

src/DependencyInjection/CacheExtension.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,32 @@ public function load(array $configs, ContainerBuilder $container)
5353
if ($container->getParameter('kernel.debug')) {
5454
$loader->load('data-collector.yml');
5555
}
56+
57+
$serviceIds = array();
58+
$this->findServiceIds($config, $serviceIds);
59+
$container->setParameter('cache.provider.serviceIds', $serviceIds);
5660
}
5761

62+
/**
63+
* Find service ids that we configured.
64+
*
65+
* @param array $config
66+
* @param array $serviceIds
67+
*/
68+
protected function findServiceIds(array $config, array &$serviceIds)
69+
{
70+
foreach ($config as $name=>$value) {
71+
if (is_array($value)) {
72+
$this->findServiceIds($value, $serviceIds);
73+
} elseif ($name === 'service_id') {
74+
$serviceIds[] = $value;
75+
}
76+
}
77+
}
78+
79+
/**
80+
* @return string
81+
*/
5882
public function getAlias()
5983
{
6084
return 'cache';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\cache-bundle package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\CacheBundle\DependencyInjection\Compiler;
13+
14+
use Cache\CacheBundle\Cache\LoggingCachePool;
15+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
19+
/**
20+
* Make sure to tag all cache provider used.
21+
*
22+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
23+
*/
24+
class CacheTaggingPass implements CompilerPassInterface
25+
{
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function process(ContainerBuilder $container)
30+
{
31+
// get service ids form parameters
32+
$serviceIds = $container->getParameter('cache.provider.serviceIds');
33+
34+
foreach ($serviceIds as $id) {
35+
36+
$def = $container->findDefinition($id);
37+
if (!$def->hasTag('cache.provider')) {
38+
$def->addTag('cache.provider');
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)