Completed
Push — master ( b288e2...4e6c2b )
by Michael
05:02 queued 02:08
created

OsLabSecurityApiExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1
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