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->loadParameters($container, $loader); |
38
|
|
|
$this->loadServices($loader); |
39
|
|
|
$this->loadCodeGenerators($container, $config); |
|
|
|
|
40
|
|
|
$this->loadDataFixtures($container, $loader); |
|
|
|
|
41
|
|
|
$this->loadBlasts($container, $loader); |
42
|
|
|
$this->loadSecurity($container); |
|
|
|
|
43
|
|
|
$this->loadSonataAdmin($container, $loader); |
44
|
|
|
$this->loadListeners($container, $config); |
|
|
|
|
45
|
|
|
$this->doLoad($container, $loader, $config); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return self |
50
|
|
|
*/ |
51
|
|
|
public function initialize() |
52
|
|
|
{ |
53
|
|
|
$rc = new \ReflectionClass($this); |
54
|
|
|
$this->dir = dirname($rc->getFileName()); |
|
|
|
|
55
|
|
|
$this->prefix = '/../Resources/config/'; |
|
|
|
|
56
|
|
|
$this->bundlesPrefix = $this->prefix . 'bundles/'; |
|
|
|
|
57
|
|
|
$this->suffix = '.yml'; |
|
|
|
|
58
|
|
|
$this->file = 'blast'; |
|
|
|
|
59
|
|
|
|
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* the buildLoader returns the required FileLoader. |
65
|
|
|
* |
66
|
|
|
* @param ContainerBuilder $container |
67
|
|
|
* |
68
|
|
|
* @return FileLoader |
69
|
|
|
*/ |
70
|
|
|
public function buildLoader(ContainerBuilder $container) |
71
|
|
|
{ |
72
|
|
|
return new YamlFileLoader($container, new FileLocator($this->dir . $this->prefix)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* This method is called during the self::load() process, to add the logic related to SonataAdmin. |
77
|
|
|
* |
78
|
|
|
* @param FileLoader $loader |
79
|
|
|
* |
80
|
|
|
* @return self |
81
|
|
|
*/ |
82
|
|
View Code Duplication |
public function loadServices(FileLoader $loader) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
if (file_exists($this->dir . $this->prefix . 'services' . $this->suffix)) { |
85
|
|
|
$loader->load('services' . $this->suffix); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* This method is called after loading the services in the self::load() process, to load code generators. |
93
|
|
|
* |
94
|
|
|
* @param ContainerBuilder $container |
95
|
|
|
* @param array $config |
96
|
|
|
* |
97
|
|
|
* @return self |
98
|
|
|
*/ |
99
|
|
|
public function loadCodeGenerators(ContainerBuilder $container, array $config) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* This method is called after loading the services in the self::load() process, to load data fixtures. |
106
|
|
|
* |
107
|
|
|
* @param ContainerBuilder $container |
108
|
|
|
* @param FileLoader $loader |
109
|
|
|
* |
110
|
|
|
* @return self |
111
|
|
|
*/ |
112
|
|
|
public function loadDataFixtures(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param ContainerBuilder $container |
119
|
|
|
* |
120
|
|
|
* @return self |
121
|
|
|
*/ |
122
|
|
|
public function loadBlasts(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
// the blast.yml |
125
|
|
|
if (file_exists($this->dir . $this->prefix . $this->file . $this->suffix)) { |
126
|
|
|
$this->mergeParameter('blast', $container, $this->dir . $this->prefix); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param ContainerBuilder $container |
134
|
|
|
* |
135
|
|
|
* @return self |
136
|
|
|
*/ |
137
|
|
View Code Duplication |
public function loadParameters(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
// parameters.yml |
140
|
|
|
if (file_exists($this->dir . $this->prefix . 'parameters' . $this->suffix)) { |
141
|
|
|
$loader->load('parameters' . $this->suffix); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* This method is called at the end of the self::load() process, to add security related logic. |
149
|
|
|
* |
150
|
|
|
* @param ContainerBuilder $container |
151
|
|
|
* |
152
|
|
|
* @return self |
153
|
|
|
*/ |
154
|
|
|
public function loadSecurity(ContainerBuilder $container) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* This method is called at the end of the self::load() process, to add the logic related to SonataAdmin. |
161
|
|
|
* |
162
|
|
|
* @param ContainerBuilder $container |
163
|
|
|
* @param FileLoader $loader |
164
|
|
|
* |
165
|
|
|
* @return self |
166
|
|
|
*/ |
167
|
|
|
public function loadSonataAdmin(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
168
|
|
|
{ |
169
|
|
|
if (file_exists($path = $this->dir . $this->bundlesPrefix . 'sonata_admin' . $this->suffix)) { |
|
|
|
|
170
|
|
|
$configSonataAdmin = Yaml::parse( |
171
|
|
|
file_get_contents($path) |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
DefaultParameters::getInstance($container)->defineDefaultConfiguration($configSonataAdmin['default']); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* This method is called during the self::load() process, to add the logic related to SonataAdmin. |
182
|
|
|
* |
183
|
|
|
* @param ContainerBuilder $container |
184
|
|
|
* @param array $config |
185
|
|
|
* |
186
|
|
|
* @return self |
187
|
|
|
*/ |
188
|
|
|
public function loadListeners(ContainerBuilder $container, array $config) |
|
|
|
|
189
|
|
|
{ |
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* This method is called at the end of the self::load() process, to add any logic needed. |
195
|
|
|
* |
196
|
|
|
* @param ContainerBuilder $container |
197
|
|
|
* @param FileLoader $loader |
198
|
|
|
* @param array $config |
199
|
|
|
* |
200
|
|
|
* @return self |
201
|
|
|
*/ |
202
|
|
|
public function doLoad(ContainerBuilder $container, FileLoader $loader, array $config) |
|
|
|
|
203
|
|
|
{ |
204
|
|
|
return $this; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param string $var the parameter name |
209
|
|
|
* @param ContainerBuilder $container |
210
|
|
|
* @param string $dir |
211
|
|
|
* @param string $file_name |
212
|
|
|
* |
213
|
|
|
* @return self |
214
|
|
|
*/ |
215
|
|
|
protected function mergeParameter($var, $container, $dir, $file_name = 'blast.yml') |
216
|
|
|
{ |
217
|
|
|
$loader = new YamlFileLoader($newContainer = new ContainerBuilder(), new FileLocator($dir)); |
218
|
|
|
$loader->load($file_name); |
219
|
|
|
|
220
|
|
|
if (!$container->hasParameter($var) || !is_array($container->getParameter($var))) { |
221
|
|
|
$container->setParameter($var, []); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
if (!is_array($newContainer->getParameter($var))) { |
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$container->setParameter($var, array_merge( |
229
|
|
|
$container->getParameter($var), |
230
|
|
|
$newContainer->getParameter($var) |
231
|
|
|
)); |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
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: