Completed
Push — master ( e9e666...e79deb )
by Roni
01:22
created

ResolverFactoryPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 30 5
A getServiceReferenceByConfigName() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the XiideaEasyAuditBundle package.
5
 *
6
 * (c) Xiidea <http://www.xiidea.net>
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 Xiidea\EasyAuditBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class ResolverFactoryPass implements CompilerPassInterface
19
{
20
    public function process(ContainerBuilder $container)
21
    {
22
23
        if (false === $container->hasDefinition('xiidea.easy_audit.event_resolver_factory')) {
24
            return;
25
        }
26
27
        $definition = $container->getDefinition('xiidea.easy_audit.event_resolver_factory');
28
29
        $calls = $definition->getMethodCalls();
30
        $definition->setMethodCalls(array());
31
32
        foreach ($container->getParameter('xiidea.easy_audit.custom_resolvers') as $id) {
33
            if ($container->hasDefinition($id)) {
34
                $definition->addMethodCall('addCustomResolver', array($id, new Reference($id)));
35
            }
36
        }
37
38
        $definition->addMethodCall('setCommonResolver', array(
39
            $this->getServiceReferenceByConfigName($container, 'resolver'))
40
        );
41
42
        if($container->hasAlias('doctrine')) {
43
            $definition->addMethodCall('setEntityEventResolver', array(
44
                    $this->getServiceReferenceByConfigName($container, 'entity_event_resolver'))
45
            );
46
        }
47
48
        $definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
49
    }
50
51
    /**
52
     * @param ContainerBuilder $container
53
     * @param $configName
54
     * @return Reference
55
     */
56
    protected function getServiceReferenceByConfigName(ContainerBuilder $container, $configName)
57
    {
58
        return new Reference($container->getParameter('xiidea.easy_audit.' . $configName));
59
    }
60
}