Completed
Push — master ( 91bc8f...12870b )
by Nikola
05:50
created

TwigEnvironmentCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 9.2
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
/*
3
 * This file is part of the QueryResourcesLoader Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2016 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\QueryResourcesLoader\DependencyInjection\CompilerPass;
11
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
class TwigEnvironmentCompilerPass implements CompilerPassInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (false === $container->hasDefinition('run_open_code.query_resources_loader.twig')) {
24
            return;
25
        }
26
27
        $definition = $container->getDefinition('run_open_code.query_resources_loader.twig');
28
29
        // Extensions must always be registered before everything else.
30
        // For instance, global variable definitions must be registered
31
        // afterward. If not, the globals from the extensions will never
32
        // be registered.
33
        $calls = $definition->getMethodCalls();
34
35
        $definition->setMethodCalls(array());
36
37
        foreach ($container->findTaggedServiceIds('run_open_code.query_resources_loader.twig.extension') as $id => $attributes) {
38
            $definition->addMethodCall('addExtension', array(new Reference($id)));
39
        }
40
41
        $definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
42
    }
43
}
44