Completed
Push — 2.x-dev-kit ( 6f250c )
by
unknown
02:44
created

CacheCompilerPass::process()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.439
cc 6
eloc 15
nc 24
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\CacheBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
/**
19
 * @author Thomas Rabaix <[email protected]>
20
 */
21
class CacheCompilerPass implements CompilerPassInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        $caches = array();
29
30
        foreach ($container->findTaggedServiceIds('sonata.cache') as $id => $attributes) {
31
            if (!$container->hasDefinition($id)) {
32
                continue;
33
            }
34
35
            $caches[$id] = new Reference($id);
36
        }
37
38
        if ($container->hasDefinition('sonata.cache.orm.event_subscriber.default')) {
39
            $container->getDefinition('sonata.cache.orm.event_subscriber.default')
40
                ->replaceArgument(1, $caches);
41
        }
42
43
        if ($container->hasDefinition('sonata.cache.phpcr_odm.event_subscriber.default')) {
44
            $container->getDefinition('sonata.cache.phpcr_odm.event_subscriber.default')
45
                ->replaceArgument(1, $caches);
46
        }
47
48
        if ($container->hasDefinition('sonata.cache.manager')) {
49
            $container->getDefinition('sonata.cache.manager')
50
                ->replaceArgument(1, $caches);
51
        }
52
    }
53
}
54