1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TreeHouse\BaseApiBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
|
10
|
|
|
class TreeHouseBaseApiExtension extends Extension |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @inheritdoc |
14
|
|
|
*/ |
15
|
24 |
|
public function load(array $configs, ContainerBuilder $container) |
16
|
|
|
{ |
17
|
24 |
|
$configuration = new Configuration(); |
18
|
24 |
|
$config = $this->processConfiguration($configuration, $configs); |
19
|
|
|
|
20
|
24 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
21
|
24 |
|
$loader->load('services.yml'); |
22
|
|
|
|
23
|
24 |
|
$this->setParameters($container, $config); |
24
|
24 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param ContainerBuilder $container |
28
|
|
|
* @param array $config |
29
|
|
|
*/ |
30
|
24 |
|
protected function setParameters(ContainerBuilder $container, array $config) |
31
|
|
|
{ |
32
|
24 |
|
$this->setConfigParameters($container, $config, ['tree_house.api']); |
33
|
24 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param ContainerBuilder $container |
37
|
|
|
* @param array $config |
38
|
|
|
* @param array $prefixes |
39
|
|
|
*/ |
40
|
24 |
|
protected function setConfigParameters(ContainerBuilder $container, array $config, array $prefixes = []) |
41
|
|
|
{ |
42
|
24 |
|
foreach ($config as $key => $value) { |
43
|
24 |
|
$newPrefixes = array_merge($prefixes, [$key]); |
44
|
|
|
|
45
|
24 |
|
if (is_array($value) && !is_numeric(key($value))) { |
46
|
|
|
$this->setConfigParameters($container, $value, $newPrefixes); |
47
|
|
|
|
48
|
|
|
continue; |
49
|
|
|
} |
50
|
|
|
|
51
|
24 |
|
$name = implode('.', $newPrefixes); |
52
|
24 |
|
$container->setParameter($name, $value); |
53
|
12 |
|
} |
54
|
24 |
|
} |
55
|
|
|
} |
56
|
|
|
|