RegistryParametersResolversPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 33 6
1
<?php
2
3
/*
4
 * This file is part of the I18n Routing Bundle.
5
 *
6
 * (c) Beñat Espiña <[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 BenatEspina\I18nRoutingBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
class RegistryParametersResolversPass implements CompilerPassInterface
21
{
22
    const SERVICE_ID = 'benat_espina_i18n_routing.resolver.parameters_resolver_registry';
23
24
    public function process(ContainerBuilder $container)
25
    {
26
        if (!$container->hasDefinition(self::SERVICE_ID)) {
27
            return;
28
        }
29
30
        $config = $container->getParameter('benat_espina_i18n_routing.config');
31
        $services = $container->findTaggedServiceIds('benat_espina_i18n_routing.parameters_resolver');
32
33
        $parametersResolvers = [];
34
        foreach ($services as $serviceId => $tags) {
35
            foreach ($tags as $attributes) {
36
                if (!isset($attributes['alias'])) {
37
                    throw new \LogicException(
38
                        'All the services tagged by "benat_espina_i18n_routing.parameters_resolver" ' .
39
                        'must have "alias" property'
40
                    );
41
                }
42
                if ($attributes['alias'] === $config['default_parameters_resolver']) {
43
                    $container->findDefinition(self::SERVICE_ID)->replaceArgument(
44
                        1,
45
                        $container->getDefinition($serviceId)
46
                    );
47
                    continue;
48
                }
49
                $parametersResolvers[] = $container->getDefinition($serviceId);
50
            }
51
        }
52
        $container->findDefinition(self::SERVICE_ID)->replaceArgument(
53
            0,
54
            $parametersResolvers
55
        );
56
    }
57
}
58