|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the OneGuard DynamicConfigurationBundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) OneGuard <[email protected]> |
|
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 OneGuard\Bundle\DynamicConfigurationBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use OneGuard\Bundle\DynamicConfigurationBundle\DefinitionRegistry; |
|
15
|
|
|
use Symfony\Component\Config\FileLocator; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
19
|
|
|
|
|
20
|
|
|
class OneGuardDynamicConfigurationExtension extends Extension { |
|
21
|
|
|
/** |
|
22
|
|
|
* @param array $configs |
|
23
|
|
|
* @param ContainerBuilder $container |
|
24
|
|
|
* @throws \Exception |
|
25
|
|
|
*/ |
|
26
|
|
|
public function load(array $configs, ContainerBuilder $container) { |
|
27
|
|
|
$loader = new YamlFileLoader( |
|
28
|
|
|
$container, |
|
29
|
|
|
new FileLocator(__DIR__.'/../Resources/config') |
|
30
|
|
|
); |
|
31
|
|
|
$loader->load('services.yml'); |
|
32
|
|
|
|
|
33
|
|
|
$configuration = new Configuration(); |
|
34
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
35
|
|
|
|
|
36
|
|
|
$container->setParameter('one_guard.dynamic_configuration.translation_domain', $config['translation_domain']); |
|
37
|
|
|
$container->setParameter('one_guard.dynamic_configuration.translation_prefix', $config['translation_prefix']); |
|
38
|
|
|
|
|
39
|
|
|
$register = $container->getDefinition(DefinitionRegistry::class); |
|
40
|
|
|
|
|
41
|
|
|
foreach ($config['definitions'] as $key => $definitionConfig) { |
|
42
|
|
|
switch ($definitionConfig['type']) { |
|
43
|
|
|
case 'entity': |
|
44
|
|
|
$register->addMethodCall('registerEntity', [ |
|
45
|
|
|
$key, |
|
46
|
|
|
$definitionConfig['options']['class'], |
|
47
|
|
|
$definitionConfig['options']['choice_label'] |
|
48
|
|
|
]); |
|
49
|
|
|
break; |
|
50
|
|
|
case 'string': |
|
51
|
|
|
$register->addMethodCall('registerString', [$key]); |
|
52
|
|
|
break; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|