Completed
Push — master ( fc0488...e7fa5b )
by Michael
10:16 queued 07:42
created

OsLabSecurityApiExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 43
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 10 1
B remapParametersNamespaces() 0 17 6
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\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
17
use Symfony\Component\DependencyInjection\Loader;
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, array('authentication' => "oslab_security_api.authentication.%s"));
39 3
    }
40
41
    /**
42
     * Maps parameters to add them in container.
43
     *
44
     * @param array            $config     The gloabl 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
     * @return void
49
     */
50 3
    protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces)
51
    {
52 3
        foreach ($namespaces as $namespace => $map) {
53 3
            if (isset($namespace) && strlen($namespace) > 0) {
54 3
                if (!array_key_exists($namespace, $config)) {
55
                    continue;
56
                }
57 3
                $namespaceConfig = $config[$namespace];
58
            } else {
59
                $namespaceConfig = $config;
60
            }
61
62 3
            foreach ($namespaceConfig as $name => $value) {
63 3
                $container->setParameter(sprintf($map, $name), $value);
64
            }
65
        }
66 3
    }
67
}
68