Completed
Pull Request — develop (#28)
by A.
06:11
created

parseAvailableLocaleConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4286
cc 1
eloc 7
nc 1
nop 2
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($config['locale_cookie_domain'], $config['locale_cookie_key'], $container);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
39
        $this->parseDefaultLocaleConfiguration($config['default_locale'], $container);
40
        $this->parseAvailableLocaleConfiguration($config['locales'], $container);
41
    }
42
43
    private function parseDefaultLocaleConfiguration($defaultLocaleConfig, ContainerBuilder $container)
44
    {
45
        $container
46
            ->getDefinition('profile.default_locale')
47
            ->replaceArgument(0, $defaultLocaleConfig);
48
    }
49
50
    private function parseAvailableLocaleConfiguration(array $availableLocaleConfig, ContainerBuilder $container)
51
    {
52
        $availableLocales = array_map(function ($availableLocale) {
53
            return new Definition('OpenConext\Profile\Value\Locale', [$availableLocale]);
54
        }, $availableLocaleConfig);
55
56
        $container
57
            ->getDefinition('profile.available_locales')
58
            ->replaceArgument(0, $availableLocales);
59
    }
60
61
    private function parseCookieStorageConfiguration($localeCookieDomain, $localeCookieKey, ContainerBuilder $container)
62
    {
63
        $container
64
            ->getDefinition('profile.storage.locale_cookie')
65
            ->replaceArgument(0, $localeCookieDomain)
66
            ->replaceArgument(1, $localeCookieKey);
67
    }
68
}
69