Completed
Push — master ( db7eb5...55f7f1 )
by Tobias
22:14
created

LoggerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 29
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 21 5
1
<?php
2
3
/*
4
 * This file is part of php-cache\cache-bundle package.
5
 *
6
 * (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
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 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
/**
19
 * Add logging to pool implementing LoggerAwareInterface.
20
 *
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
class LoggerPass implements CompilerPassInterface
24
{
25
    /**
26
     * @param ContainerBuilder $container
27
     *
28
     * @throws \Exception
29
     */
30
    public function process(ContainerBuilder $container)
31
    {
32
        if (!$container->hasParameter('cache.logging')) {
33
            return;
34
        }
35
36
        $config = $container->getParameter('cache.logging');
37
        if (!$config['enabled']) {
38
            return;
39
        }
40
41
        $serviceIds = $container->findTaggedServiceIds('cache.provider');
42
43
        foreach (array_keys($serviceIds) as $id) {
44
            $poolDefinition = $container->getDefinition($id);
45
            if (!method_exists($poolDefinition->getClass(), 'setLogger')) {
46
                continue;
47
            }
48
            $poolDefinition->addMethodCall('setLogger', [new Reference($config['logger'])]);
49
        }
50
    }
51
}
52