replaceLoaAliasConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 2
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2016 SURFnet bv
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 Surfnet\StepupGateway\SecondFactorOnlyBundle\DependencyInjection;
20
21
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
22
use Symfony\Component\Config\FileLocator;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
25
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
26
27
/**
28
 * @SuppressWarnings(PHPMD.LongClassName)
29
 */
30
class SurfnetStepupGatewaySecondFactorOnlyExtension extends Extension
31
{
32
    public function load(array $config, ContainerBuilder $container): void
33
    {
34
        $loader = new YamlFileLoader(
35
            $container,
36
            new FileLocator(__DIR__ . '/../Resources/config')
37
        );
38
        $loader->load('services.yml');
39
40
        $this->replaceLoaAliasConfig($config, $container);
41
    }
42
43
    /**
44
     * @param array $config
45
     * @param ContainerBuilder $container
46
     */
47
    private function replaceLoaAliasConfig(
48
        array $config,
49
        ContainerBuilder $container
50
    ): void {
51
        $loaAliasMapping = [];
52
        foreach ($config[0]['loa_aliases'] as $mapping) {
53
            if (isset($loaAliasMapping[$mapping['loa']])) {
54
                throw new InvalidConfigurationException(
55
                    'Duplicate loa identifiers in surfnet_stepup_gateway_gateway.loa_domains.gateway'
56
                );
57
            }
58
59
            $loaAliasMapping[$mapping['loa']] = $mapping['alias'];
60
        }
61
        $container
62
            ->getDefinition('second_factor_only.loa_alias_lookup')
63
            ->replaceArgument(0, $loaAliasMapping);
64
    }
65
}
66