GeneratorCompilerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
rs 9.2
cc 4
eloc 9
nc 4
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Knowledge Base package.
5
 *
6
 * Copyright (c) 2015 LIN3S <[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 LIN3S\KnowledgeBaseBundle\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
 * Class ConfigurationCompilerPass.
20
 *
21
 * Loads config from parameters and adds definitions in the container for template and configuration as
22
 * 'lin3s_knowledge_base.template' and 'lin3s_knowledge_base.configuration' respectively.
23
 *
24
 * @author Gorka Laucirica <[email protected]>
25
 */
26
class GeneratorCompilerPass implements CompilerPassInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process(ContainerBuilder $container)
32
    {
33
        if (!$container->hasDefinition('lin3s_knowledge_base.registry.generator')) {
34
            return;
35
        }
36
        $registry = $container->getDefinition('lin3s_knowledge_base.registry.generator');
37
        foreach ($container->findTaggedServiceIds('lin3s_knowledge_base.generator') as $id => $attributes) {
38
            if (!isset($attributes[0]['label'])) {
39
                throw new \InvalidArgumentException('Tagged generator needs to have `label` attribute.');
40
            }
41
            $name = $attributes[0]['label'];
42
            $registry->addMethodCall('add', [$name, new Reference($id)]);
43
        }
44
    }
45
}
46