1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
6
|
|
|
* |
7
|
|
|
* This file is licenced under the GNU LGPL v3. |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Blast\Bundle\CoreBundle\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\FileLoader; |
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
19
|
|
|
use Symfony\Component\Yaml\Yaml; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This is the class that loads and manages your bundle configuration. |
23
|
|
|
* |
24
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
25
|
|
|
*/ |
26
|
|
|
class BlastCoreExtension extends Extension |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function load(array $configs, ContainerBuilder $container) |
32
|
|
|
{ |
33
|
|
|
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs); |
|
|
|
|
34
|
|
|
$this->initialize(); |
35
|
|
|
$loader = $this->buildLoader($container); |
36
|
|
|
|
37
|
|
|
$this->loadServices($loader); |
38
|
|
|
$this->loadCodeGenerators($container, $config); |
|
|
|
|
39
|
|
|
$this->loadDataFixtures($container, $loader); |
|
|
|
|
40
|
|
|
$this->loadParameters($container); |
41
|
|
|
$this->loadSecurity($container); |
|
|
|
|
42
|
|
|
$this->loadSonataAdmin($container, $loader); |
43
|
|
|
$this->loadListeners($container, $config); |
|
|
|
|
44
|
|
|
$this->doLoad($container, $loader, $config); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return self |
49
|
|
|
*/ |
50
|
|
|
public function initialize() |
51
|
|
|
{ |
52
|
|
|
$rc = new \ReflectionClass($this); |
53
|
|
|
$this->dir = dirname($rc->getFileName()); |
|
|
|
|
54
|
|
|
$this->prefix = '/../Resources/config/'; |
|
|
|
|
55
|
|
|
$this->bundlesPrefix = $this->prefix . 'bundles/'; |
|
|
|
|
56
|
|
|
$this->suffix = '.yml'; |
|
|
|
|
57
|
|
|
$this->file = 'blast'; |
|
|
|
|
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* the buildLoader returns the required FileLoader. |
64
|
|
|
* |
65
|
|
|
* @param ContainerBuilder $container |
66
|
|
|
* |
67
|
|
|
* @return FileLoader |
68
|
|
|
*/ |
69
|
|
|
public function buildLoader(ContainerBuilder $container) |
70
|
|
|
{ |
71
|
|
|
return new YamlFileLoader($container, new FileLocator($this->dir . $this->prefix)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* This method is called during the self::load() process, to add the logic related to SonataAdmin. |
76
|
|
|
* |
77
|
|
|
* @param FileLoader $loader |
78
|
|
|
* |
79
|
|
|
* @return self |
80
|
|
|
*/ |
81
|
|
|
public function loadServices(FileLoader $loader) |
82
|
|
|
{ |
83
|
|
|
// services, admin & config files |
84
|
|
|
foreach (['services', 'admin'] as $fileName) { |
85
|
|
|
if (file_exists($this->dir . $this->prefix . $fileName . $this->suffix)) { |
86
|
|
|
$loader->load($fileName . $this->suffix); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* This method is called after loading the services in the self::load() process, to load code generators. |
95
|
|
|
* |
96
|
|
|
* @param ContainerBuilder $container |
97
|
|
|
* @param array $config |
98
|
|
|
* |
99
|
|
|
* @return self |
100
|
|
|
*/ |
101
|
|
|
public function loadCodeGenerators(ContainerBuilder $container, array $config) |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* This method is called after loading the services in the self::load() process, to load data fixtures. |
108
|
|
|
* |
109
|
|
|
* @param ContainerBuilder $container |
110
|
|
|
* @param FileLoader $loader |
111
|
|
|
* |
112
|
|
|
* @return self |
113
|
|
|
*/ |
114
|
|
|
public function loadDataFixtures(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* This method is called after loading the services in the self::load() process, to load data fixtures. |
121
|
|
|
* |
122
|
|
|
* @param ContainerBuilder $container |
123
|
|
|
* |
124
|
|
|
* @return self |
125
|
|
|
*/ |
126
|
|
|
public function loadParameters(ContainerBuilder $container) |
127
|
|
|
{ |
128
|
|
|
// the blast.yml |
129
|
|
|
if (file_exists($this->dir . $this->prefix . $this->file . $this->suffix)) { |
130
|
|
|
$this->mergeParameter('blast', $container, $this->dir . $this->prefix); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* This method is called at the end of the self::load() process, to add security related logic. |
138
|
|
|
* |
139
|
|
|
* @param ContainerBuilder $container |
140
|
|
|
* |
141
|
|
|
* @return self |
142
|
|
|
*/ |
143
|
|
|
public function loadSecurity(ContainerBuilder $container) |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* This method is called at the end of the self::load() process, to add the logic related to SonataAdmin. |
150
|
|
|
* |
151
|
|
|
* @param ContainerBuilder $container |
152
|
|
|
* @param FileLoader $loader |
153
|
|
|
* |
154
|
|
|
* @return self |
155
|
|
|
*/ |
156
|
|
|
public function loadSonataAdmin(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
if (file_exists($path = $this->dir . $this->bundlesPrefix . 'sonata_admin' . $this->suffix)) { |
|
|
|
|
159
|
|
|
$configSonataAdmin = Yaml::parse( |
160
|
|
|
file_get_contents($path) |
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
DefaultParameters::getInstance($container)->defineDefaultConfiguration($configSonataAdmin['default']); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* This method is called during the self::load() process, to add the logic related to SonataAdmin. |
171
|
|
|
* |
172
|
|
|
* @param ContainerBuilder $container |
173
|
|
|
* @param array $config |
174
|
|
|
* |
175
|
|
|
* @return self |
176
|
|
|
*/ |
177
|
|
|
public function loadListeners(ContainerBuilder $container, array $config) |
|
|
|
|
178
|
|
|
{ |
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* This method is called at the end of the self::load() process, to add any logic needed. |
184
|
|
|
* |
185
|
|
|
* @param ContainerBuilder $container |
186
|
|
|
* @param FileLoader $loader |
187
|
|
|
* @param array $config |
188
|
|
|
* |
189
|
|
|
* @return self |
190
|
|
|
*/ |
191
|
|
|
public function doLoad(ContainerBuilder $container, FileLoader $loader, array $config) |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param string $var the parameter name |
198
|
|
|
* @param ContainerBuilder $container |
199
|
|
|
* @param string $dir |
200
|
|
|
* @param string $file_name |
201
|
|
|
* |
202
|
|
|
* @return self |
203
|
|
|
*/ |
204
|
|
|
protected function mergeParameter($var, $container, $dir, $file_name = 'blast.yml') |
205
|
|
|
{ |
206
|
|
|
$loader = new YamlFileLoader($newContainer = new ContainerBuilder(), new FileLocator($dir)); |
207
|
|
|
$loader->load($file_name); |
208
|
|
|
|
209
|
|
|
if (!$container->hasParameter($var) || !is_array($container->getParameter($var))) { |
210
|
|
|
$container->setParameter($var, []); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
if (!is_array($newContainer->getParameter($var))) { |
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
$container->setParameter($var, array_merge( |
218
|
|
|
$container->getParameter($var), |
219
|
|
|
$newContainer->getParameter($var) |
220
|
|
|
)); |
221
|
|
|
|
222
|
|
|
return $this; |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: