remapParametersNamespaces()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.3949

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 7
cts 9
cp 0.7778
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 10
nc 4
nop 3
crap 6.3949
1
<?php
2
3
/*
4
 * This file is part of the OsLabSecurityApiBundle package.
5
 *
6
 * (c) OsLab <https://github.com/OsLab>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace OsLab\SecurityApiBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Loader;
17
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18
19
/**
20
 * Class load bundle extension.
21
 *
22
 * @author Michael COULLERET <[email protected]>
23
 * @author Florent DESPIERRES <[email protected]>
24
 */
25
class OsLabSecurityApiExtension extends Extension
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30 3
    public function load(array $configs, ContainerBuilder $container)
31
    {
32 3
        $configuration = new Configuration();
33 3
        $config = $this->processConfiguration($configuration, $configs);
34
35 3
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
36 3
        $loader->load('security.yml');
37
38 3
        $this->remapParametersNamespaces($config, $container, ['authentication' => 'oslab_security_api.authentication.%s']);
39 3
    }
40
41
    /**
42
     * Maps parameters to add them in container.
43
     *
44
     * @param array            $config     the global config of this bundle
45
     * @param ContainerBuilder $container  the container for dependency injection
46
     * @param array            $namespaces config namespaces to add as parameters in the container
47
     */
48
    protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces)
49
    {
50 3
        foreach ($namespaces as $namespace => $map) {
51
            if (isset($namespace) && strlen($namespace) > 0) {
52 3
                if (!array_key_exists($namespace, $config)) {
53 3
                    continue;
54 3
                }
55
                $namespaceConfig = $config[$namespace];
56
            } else {
57 3
                $namespaceConfig = $config;
58
            }
59
60
            foreach ($namespaceConfig as $name => $value) {
61
                $container->setParameter(sprintf($map, $name), $value);
62 3
            }
63 3
        }
64
    }
65
}
66