Completed
Pull Request — develop (#79)
by
unknown
01:48
created

parseLocaleCookieStorageConfiguration()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 6
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
use \DateTime;
27
28
class OpenConextProfileExtension extends Extension
29
{
30
    public function load(array $configs, ContainerBuilder $container)
31
    {
32
        $configuration = new Configuration();
33
        $config        = $this->processConfiguration($configuration, $configs);
34
35
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
36
        $loader->load('controllers.yml');
37
        $loader->load('services.yml');
38
39
        $this->parseEngineBlockEntityIdConfiguration($config['engine_block_entity_id'], $container);
40
41
        $this->parseAttributeSupportMailConfiguration($config['attribute_support'], $container);
42
        $this->parseInformationRequestMailConfiguration($config['information_request'], $container);
43
44
        $this->parseDefaultLocaleConfiguration($config['default_locale'], $container);
45
        $this->parseAvailableLocaleConfiguration($config['locales'], $container);
46
        $this->parseLocaleCookieStorageConfiguration(
47
            $config['locale_cookie_domain'],
48
            $config['locale_cookie_key'],
49
            $config['locale_cookie_expires_in'],
50
            $config['locale_cookie_secure'],
51
            $config['locale_cookie_http_only'],
52
            $container
53
        );
54
    }
55
56
    private function parseEngineBlockEntityIdConfiguration($engineBlockEntityId, ContainerBuilder $container)
57
    {
58
        $container
59
            ->getDefinition('profile.engine_block_entity_id')
60
            ->replaceArgument(0, $engineBlockEntityId);
61
    }
62
63
    private function parseAttributeSupportMailConfiguration(array $attributeSupportConfig, ContainerBuilder $container)
64
    {
65
        $container
66
            ->getDefinition('profile.attribute_support.email_from')
67
            ->replaceArgument(0, $attributeSupportConfig['email_from']);
68
        $container
69
            ->getDefinition('profile.attribute_support.email_to')
70
            ->replaceArgument(0, $attributeSupportConfig['email_to']);
71
    }
72
73
    private function parseInformationRequestMailConfiguration(array $attributeSupportConfig, ContainerBuilder $container)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 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...
74
    {
75
        $container
76
            ->getDefinition('profile.information_request.email_from')
77
            ->replaceArgument(0, $attributeSupportConfig['email_from']);
78
        $container
79
            ->getDefinition('profile.information_request.email_to')
80
            ->replaceArgument(0, $attributeSupportConfig['email_to']);
81
    }
82
83
    private function parseDefaultLocaleConfiguration($defaultLocaleConfig, ContainerBuilder $container)
84
    {
85
        $container
86
            ->getDefinition('profile.default_locale')
87
            ->replaceArgument(0, $defaultLocaleConfig);
88
    }
89
90
    private function parseAvailableLocaleConfiguration(array $availableLocaleConfig, ContainerBuilder $container)
91
    {
92
        $availableLocales = array_map(function ($availableLocale) {
93
            return new Definition('OpenConext\Profile\Value\Locale', [$availableLocale]);
94
        }, $availableLocaleConfig);
95
96
        $container
97
            ->getDefinition('profile.available_locales')
98
            ->replaceArgument(0, $availableLocales);
99
    }
100
101
    private function parseLocaleCookieStorageConfiguration(
102
        $localeCookieDomain,
103
        $localeCookieKey,
104
        $localeCookieExpiresIn,
105
        $localeCookieSecure,
106
        $localeCookieHttpOnly,
107
        ContainerBuilder $container
108
    ) {
109
110
        if ($localeCookieExpiresIn !== null) {
111
            $localeCookieExpirationDateDefinition = new Definition(DateTime::class);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $localeCookieExpirationDateDefinition exceeds the maximum configured length of 30.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
112
            $localeCookieExpirationDateDefinition->addMethodCall('modify', [$localeCookieExpiresIn]);
113
        } else {
114
            $localeCookieExpirationDateDefinition = null;
115
        }
116
117
        $container
118
            ->getDefinition('profile.storage.locale_cookie')
119
            ->replaceArgument(0, $localeCookieDomain)
120
            ->replaceArgument(1, $localeCookieKey)
121
            ->replaceArgument(2, $localeCookieExpirationDateDefinition)
122
            ->replaceArgument(3, $localeCookieSecure)
123
            ->replaceArgument(4, $localeCookieHttpOnly);
124
    }
125
}
126