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
|
|
|
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('security.yml'); |
37
|
|
|
|
38
|
|
|
$this->remapParametersNamespaces($config, $container, array('authentication' => "oslab_security_api.authentication.%s")); |
39
|
|
|
} |
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
|
|
|
protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces) |
51
|
|
|
{ |
52
|
|
|
foreach ($namespaces as $namespace => $map) { |
53
|
|
|
if (isset($namespace) && strlen($namespace) > 0) { |
54
|
|
|
if (!array_key_exists($namespace, $config)) { |
55
|
|
|
continue; |
56
|
|
|
} |
57
|
|
|
$namespaceConfig = $config[$namespace]; |
58
|
|
|
} else { |
59
|
|
|
$namespaceConfig = $config; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
foreach ($namespaceConfig as $name => $value) { |
63
|
|
|
$container->setParameter(sprintf($map, $name), $value); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|