TwigPass::process()   B
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 15
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel package.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[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 LIN3S\CMSKernel\Infrastructure\Lin3sAdminBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
class TwigPass implements CompilerPassInterface
21
{
22
    public function process(ContainerBuilder $container)
23
    {
24
        $config = $container->getParameter('cms_kernel_admin_bridge.config');
25
26
        $resultLocales = [];
27
        foreach ($config['locales'] as $localeType => $locales) {
28
            if ($localeType === 'default') {
29
                $resultLocales[] = $locales;
30
            } else {
31
                foreach ($locales as $locale) {
32
                    $resultLocales[] = $locale;
33
                }
34
            }
35
        }
36
37
        $cmsKernelAdminBridge = [
38
            'user_type' => $config['user_type'],
39
            'locales'   => $resultLocales,
40
        ];
41
42
        $container->getDefinition('twig')->addMethodCall(
43
            'addGlobal', [
44
                'cms_kernel_admin_bridge', $cmsKernelAdminBridge,
45
            ]
46
        );
47
    }
48
}
49