Completed
Pull Request — develop (#38)
by A.
02:33
created

parseEngineBlockEntityIdConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
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->parseEngineBlockEntityIdConfiguration($config['engine_block_entity_id'], $container);
39
40
        $this->parseDefaultLocaleConfiguration($config['default_locale'], $container);
41
        $this->parseAvailableLocaleConfiguration($config['locales'], $container);
42
        $this->parseCookieStorageConfiguration(
43
            $config['locale_cookie_domain'],
44
            $config['locale_cookie_key'],
45
            $container
46
        );
47
    }
48
49
    private function parseEngineBlockEntityIdConfiguration($engineBlockEntityId, ContainerBuilder $container)
50
    {
51
        $container
52
            ->getDefinition('profile.engine_block_entity_id')
53
            ->replaceArgument(0, $engineBlockEntityId);
54
    }
55
56
    private function parseDefaultLocaleConfiguration($defaultLocaleConfig, ContainerBuilder $container)
57
    {
58
        $container
59
            ->getDefinition('profile.default_locale')
60
            ->replaceArgument(0, $defaultLocaleConfig);
61
    }
62
63
    private function parseAvailableLocaleConfiguration(array $availableLocaleConfig, ContainerBuilder $container)
64
    {
65
        $availableLocales = array_map(function ($availableLocale) {
66
            return new Definition('OpenConext\Profile\Value\Locale', [$availableLocale]);
67
        }, $availableLocaleConfig);
68
69
        $container
70
            ->getDefinition('profile.available_locales')
71
            ->replaceArgument(0, $availableLocales);
72
    }
73
74
    private function parseCookieStorageConfiguration($localeCookieDomain, $localeCookieKey, ContainerBuilder $container)
75
    {
76
        $container
77
            ->getDefinition('profile.storage.locale_cookie')
78
            ->replaceArgument(0, $localeCookieDomain)
79
            ->replaceArgument(1, $localeCookieKey);
80
    }
81
}
82