Completed
Push — master ( 57a491...f9215d )
by Rafał
8s
created

AddTwigPathsPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4285
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the takeit/AmpHtmlBundle package.
5
 *
6
 * (c) Rafał Muszyński <[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 Takeit\Bundle\AmpHtmlBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
17
/**
18
 * AddTwigPathsPass adds custom Twig Loader paths.
19
 *
20
 * @author Rafał Muszyński <[email protected]>
21
 */
22
class AddTwigPathsPass implements CompilerPassInterface
23
{
24
    /**
25
     * AMP themes namespace.
26
     *
27
     * @var string
28
     */
29
    const NAMESPACE_AMP_THEMES = 'amp_themes';
30
31
    /**
32
     * Current AMP theme's namespace.
33
     *
34
     * @var string
35
     */
36
    const NAMESPACE_AMP_THEME = 'amp_theme';
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function process(ContainerBuilder $container)
42
    {
43
        $bundles = $container->getParameter('kernel.bundles');
44
        if (!isset($bundles['TwigBundle'])) {
45
            throw new \RuntimeException(
46
                'TwigBundle is not registered!'
47
            );
48
        }
49
50
        $loader = $container->getDefinition('twig.loader.filesystem');
51
        $loader->addMethodCall('addPath', [
52
            $container->getParameter('takeit_amp_html.configuration.theme.themes_path'),
53
            self::NAMESPACE_AMP_THEMES,
54
        ]);
55
56
        $loader->addMethodCall('addPath', [
57
            $container->getParameter('takeit_amp_html.configuration.theme.theme_path'),
58
            self::NAMESPACE_AMP_THEME,
59
        ]);
60
    }
61
}
62