Completed
Push — master ( c7deb4...314746 )
by Beñat
09:20 queued 06:49
created

TwigPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 2
eloc 10
nc 2
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 BenGorFile\FileBundle\Twig\DownloadExtension;
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
20
/**
21
 * Register Twig extensions compiler pass.
22
 *
23
 * Service declaration via PHP allows
24
 * more flexibility with easy customization.
25
 *
26
 * @author Beñat Espiña <[email protected]>
27
 */
28
class TwigPass implements CompilerPassInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function process(ContainerBuilder $container)
34
    {
35
        $config = $container->getParameter('bengor_file.config');
36
37
        foreach ($config['file_class'] as $key => $file) {
38
            $container->setDefinition(
39
                'bengor_file.file_bundle.twig.view_extension_' . $key,
40
                (new Definition(
41
                    DownloadExtension::class, [
42
                        $container->getDefinition('router'),
43
                        $key,
44
                    ]
45
                ))->setPublic(false)
46
            );
47
        }
48
    }
49
}
50