|
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 as BaseExtension; |
|
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 BaseExtension |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
public function getAlias() |
|
19
|
|
|
{ |
|
20
|
|
|
return 'sludio_helper'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
$configuration = new Configuration(); |
|
29
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
30
|
|
|
|
|
31
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
32
|
|
|
$files = [ |
|
33
|
|
|
'components.yml', |
|
34
|
|
|
'parameters.yml', |
|
35
|
|
|
'services.yml', |
|
36
|
|
|
]; |
|
37
|
|
|
foreach ($files as $file) { |
|
38
|
|
|
if (file_exists(__DIR__.'/../Resources/config/'.$file)) { |
|
39
|
|
|
$loader->load($file); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
foreach ($config['extensions'] as $key => $extension) { |
|
44
|
|
|
$enabled = $iterator = 0; |
|
45
|
|
|
$length = count($extension); |
|
46
|
|
|
foreach ($extension as $variable => $value) { |
|
47
|
|
|
$iterator++; |
|
48
|
|
|
if ($variable == 'enabled' && $value) { |
|
49
|
|
|
$files = [ |
|
50
|
|
|
'components.yml', |
|
51
|
|
|
'parameters.yml', |
|
52
|
|
|
'services.yml', |
|
53
|
|
|
]; |
|
54
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../'.ucfirst($key).'/Resources/config')); |
|
55
|
|
|
foreach ($files as $file) { |
|
56
|
|
|
if (file_exists(__DIR__.'/../'.ucfirst($key).'/Resources/config/'.$file)) { |
|
57
|
|
|
$loader->load($file); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
$enabled = 1; |
|
61
|
|
|
} |
|
62
|
|
|
if ($enabled === 1) { |
|
63
|
|
|
$container->setParameter('sludio_helper.'.$key.'.'.$variable, $config['extensions'][$key][$variable]); |
|
64
|
|
|
} |
|
65
|
|
|
if ($iterator === $length && $enabled === 1) { |
|
66
|
|
|
$ext = new Extension($key); |
|
67
|
|
|
if ($ext->getExtension()) { |
|
68
|
|
|
$ext->configure($container); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
foreach ($config['other'] as $key => $other) { |
|
75
|
|
|
foreach ($other as $variable => $value) { |
|
76
|
|
|
$container->setParameter('sludio_helper.'.$key.'.'.$variable, $config['other'][$key][$variable]); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.