Completed
Pull Request — master (#290)
by Leny
08:38
created

ViewReferenceBuilderCompilerPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 8.5907
cc 5
eloc 14
nc 5
nop 1
1
<?php
2
3
namespace Victoire\Bundle\ViewReferenceBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Class ViewReferenceBuilderCompilerPass.
12
 */
13
class ViewReferenceBuilderCompilerPass implements CompilerPassInterface
14
{
15
    public function process(ContainerBuilder $container)
16
    {
17
        if (!$container->hasDefinition('victoire_view_reference.builder_chain')) {
18
            return;
19
        }
20
        $definition = $container->getDefinition(
21
            'victoire_view_reference.builder_chain'
22
        );
23
        $taggedServices = $container->findTaggedServiceIds(
24
            'victoire_view_reference.view_reference.builder'
25
        );
26
        foreach ($taggedServices as $id => $tagAttributes) {
27
            foreach ($tagAttributes as $attributes) {
28
                if (!array_key_exists('view', $attributes)) {
29
                    throw new InvalidConfigurationException('View class attribute is not defined for '.$id);
30
                }
31
                $definition->addMethodCall(
32
                    'addViewReferenceBuilder',
33
                    [new Reference($id), $attributes['view']]
34
                );
35
            }
36
        }
37
    }
38
}
39