Completed
Push — develop ( 511001...8b4d6d )
by A.
03:05
created

parseCookieStorageConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\ProfileBundle\DependencyInjection;
20
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\Config\FileLocator;
23
use Symfony\Component\DependencyInjection\Definition;
24
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
25
use Symfony\Component\DependencyInjection\Loader;
26
27
class OpenConextProfileExtension extends Extension
28
{
29
    public function load(array $configs, ContainerBuilder $container)
30
    {
31
        $configuration = new Configuration();
32
        $config        = $this->processConfiguration($configuration, $configs);
33
34
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
35
        $loader->load('controllers.yml');
36
        $loader->load('services.yml');
37
38
        $this->parseCookieStorageConfiguration(
39
            $config['locale_cookie_domain'],
40
            $config['locale_cookie_key'],
41
            $container
42
        );
43
        $this->parseDefaultLocaleConfiguration($config['default_locale'], $container);
44
        $this->parseAvailableLocaleConfiguration($config['locales'], $container);
45
    }
46
47
    private function parseDefaultLocaleConfiguration($defaultLocaleConfig, ContainerBuilder $container)
48
    {
49
        $container
50
            ->getDefinition('profile.default_locale')
51
            ->replaceArgument(0, $defaultLocaleConfig);
52
    }
53
54
    private function parseAvailableLocaleConfiguration(array $availableLocaleConfig, ContainerBuilder $container)
55
    {
56
        $availableLocales = array_map(function ($availableLocale) {
57
            return new Definition('OpenConext\Profile\Value\Locale', [$availableLocale]);
58
        }, $availableLocaleConfig);
59
60
        $container
61
            ->getDefinition('profile.available_locales')
62
            ->replaceArgument(0, $availableLocales);
63
    }
64
65
    private function parseCookieStorageConfiguration($localeCookieDomain, $localeCookieKey, ContainerBuilder $container)
66
    {
67
        $container
68
            ->getDefinition('profile.storage.locale_cookie')
69
            ->replaceArgument(0, $localeCookieDomain)
70
            ->replaceArgument(1, $localeCookieKey);
71
    }
72
}
73