Completed
Push — master ( e52edd...222be8 )
by Nikola
04:48
created

TwigEnvironmentCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
crap 3
1
<?php
2
/*
3
 * This file is part of the QueryResourcesLoaderBundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 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
/**
17
 * Class TwigEnvironmentCompilerPass
18
 *
19
 * Builds Twig environment, registers its extensions.
20
 *
21
 * @package RunOpenCode\Bundle\QueryResourcesLoader\DependencyInjection\CompilerPass
22
 */
23
class TwigEnvironmentCompilerPass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function process(ContainerBuilder $container)
29
    {
30 2
        if (false === $container->hasDefinition('run_open_code.query_resources_loader.twig')) {
31 1
            return;
32
        }
33
34 1
        $definition = $container->getDefinition('run_open_code.query_resources_loader.twig');
35
36
        // Extensions must always be registered before everything else.
37
        // For instance, global variable definitions must be registered
38
        // afterward. If not, the globals from the extensions will never
39
        // be registered.
40 1
        $calls = $definition->getMethodCalls();
41
42 1
        $definition->setMethodCalls(array());
43
44 1
        foreach ($container->findTaggedServiceIds('run_open_code.query_resources_loader.twig.extension') as $id => $attributes) {
45 1
            $definition->addMethodCall('addExtension', array(new Reference($id)));
46
        }
47
48 1
        $definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
49 1
    }
50
}
51