1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sludio\HelperBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This is the class that loads and manages your bundle configuration. |
12
|
|
|
* |
13
|
|
|
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html |
14
|
|
|
*/ |
15
|
|
|
class SludioHelperExtension extends Extension |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
public function getAlias() |
19
|
|
|
{ |
20
|
|
|
return 'sludio_helper'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
private function checkExtension($key) |
24
|
|
|
{ |
25
|
|
|
$className = 'Sludio\\HelperBundle\\DependencyInjection\\Component\\'.ucfirst($key); |
26
|
|
|
if (class_exists($className)) { |
27
|
|
|
return new $className(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return null; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function load(array $configs, ContainerBuilder $container) |
37
|
|
|
{ |
38
|
|
|
$configuration = new Configuration(); |
39
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
40
|
|
|
|
41
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
42
|
|
|
$files = [ |
43
|
|
|
'components.yml', |
44
|
|
|
'parameters.yml', |
45
|
|
|
'services.yml', |
46
|
|
|
]; |
47
|
|
|
foreach ($files as $file) { |
48
|
|
|
if (file_exists(__DIR__.'/../Resources/config/'.$file)) { |
49
|
|
|
$loader->load($file); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
foreach ($config['extensions'] as $key => $extension) { |
54
|
|
|
$enabled = $iterator = 0; |
55
|
|
|
$length = count($extension); |
56
|
|
|
foreach ($extension as $variable => $value) { |
57
|
|
|
$iterator++; |
58
|
|
|
if ($variable == 'enabled' && $value) { |
59
|
|
|
$files = [ |
60
|
|
|
'components.yml', |
61
|
|
|
'parameters.yml', |
62
|
|
|
'services.yml', |
63
|
|
|
]; |
64
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../'.ucfirst($key).'/Resources/config')); |
65
|
|
|
foreach ($files as $file) { |
66
|
|
|
if (file_exists(__DIR__.'/../'.ucfirst($key).'/Resources/config/'.$file)) { |
67
|
|
|
$loader->load($file); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
$enabled = 1; |
71
|
|
|
} |
72
|
|
|
if ($enabled === 1) { |
73
|
|
|
$container->setParameter('sludio_helper.'.$key.'.'.$variable, $config['extensions'][$key][$variable]); |
74
|
|
|
} |
75
|
|
|
if ($iterator === $length && $enabled === 1) { |
76
|
|
|
if ($ext = $this->checkExtension($key)) { |
77
|
|
|
$ext->configure($container); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
foreach ($config['other'] as $key => $other) { |
84
|
|
|
if (is_array($other)) { |
85
|
|
|
foreach ($other as $variable => $value) { |
86
|
|
|
$container->setParameter('sludio_helper.'.$key.'.'.$variable, $config['other'][$key][$variable]); |
87
|
|
|
} |
88
|
|
|
} else { |
89
|
|
|
$container->setParameter('sludio_helper.'.$key, $config['other'][$key]); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |