Completed
Push — master ( 10d8a3...77db4f )
by Beñat
05:15
created

TwigPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\FileBundle\DependencyInjection\Compiler;
14
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * Register Twig services compiler pass.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class TwigPass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function process(ContainerBuilder $container)
29
    {
30
        if (!$container->hasDefinition('bengor_file.file_bundle.twig.download_extension')) {
31
            return;
32
        }
33
34
        $config = $container->getParameter('bengor_file.config');
35
36
        $handlers = [];
37
        foreach ($config['file_class'] as $key => $file) {
38
            $handlers[$key] = $container->getDefinition('bengor.file.application.query.' . $key . '_of_id');
39
        }
40
41
        $container->getDefinition('bengor_file.file_bundle.twig.download_extension')->replaceArgument(
42
            1,
43
            $handlers
44
        );
45
    }
46
}
47