Completed
Pull Request — master (#4433)
by Craig
04:46
created

ZikulaSettingsExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\SettingsModule\DependencyInjection;
15
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
19
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
21
22
class ZikulaSettingsExtension extends Extension implements PrependExtensionInterface
23
{
24
    public function prepend(ContainerBuilder $container)
25
    {
26
        $configs = $container->getExtensionConfig($this->getAlias());
27
        $zikulaSettingsConfig = $this->processConfiguration(new Configuration(), $configs);
28
        if (isset($container->getExtensions()['framework'])) {
29
            $container->prependExtensionConfig('framework', [
30
                'default_locale' => $zikulaSettingsConfig['locale']
31
            ]);
32
        }
33
        if (isset($container->getExtensions()['bazinga_js_translation'])) {
34
            $container->prependExtensionConfig('bazinga_js_translation', [
35
                'locale_fallback' => $zikulaSettingsConfig['locale'],
36
                'active_locales' => $zikulaSettingsConfig['locales']
37
            ]);
38
        }
39
        if (isset($container->getExtensions()['jms_i18n_routing'])) {
40
            $container->prependExtensionConfig('jms_i18n_routing', [
41
                'default_locale' => $zikulaSettingsConfig['locale'],
42
                'locales' => $zikulaSettingsConfig['locales']
43
            ]);
44
        }
45
        if (isset($container->getExtensions()['php_translation'])) {
46
            $container->prependExtensionConfig('php_translation', [
47
                'locales' => $zikulaSettingsConfig['locales']
48
            ]);
49
        }
50
    }
51
52
    public function load(array $configs, ContainerBuilder $container)
53
    {
54
        $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__) . '/Resources/config'));
55
        $loader->load('services.yaml');
56
57
        $configuration = new Configuration();
58
        $config = $this->processConfiguration($configuration, $configs);
59
60
        $container->setParameter('locale', $config['locale']);
61
        $container->setParameter('localisation.locales', $config['locales']);
62
    }
63
}
64