File tree Expand file tree Collapse file tree 5 files changed +26
-3
lines changed
src/Symfony/Component/DependencyInjection Expand file tree Collapse file tree 5 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -271,12 +271,16 @@ public function addClassResource(\ReflectionClass $class)
271
271
* @throws BadMethodCallException When this ContainerBuilder is frozen
272
272
* @throws \LogicException if the container is frozen
273
273
*/
274
- public function loadFromExtension ($ extension , array $ values = array () )
274
+ public function loadFromExtension ($ extension , array $ values = null )
275
275
{
276
276
if ($ this ->isFrozen ()) {
277
277
throw new BadMethodCallException ('Cannot load from an extension on a frozen container. ' );
278
278
}
279
279
280
+ if (func_num_args () < 2 ) {
281
+ $ values = array ();
282
+ }
283
+
280
284
$ namespace = $ this ->getExtension ($ extension )->getAlias ();
281
285
282
286
$ this ->extensionConfigs [$ namespace ][] = $ values ;
Original file line number Diff line number Diff line change @@ -425,7 +425,7 @@ private function loadFromExtensions(array $content)
425
425
continue ;
426
426
}
427
427
428
- if (!is_array ($ values )) {
428
+ if (!is_array ($ values ) && null !== $ values ) {
429
429
$ values = array ();
430
430
}
431
431
Original file line number Diff line number Diff line change @@ -8,7 +8,14 @@ class ProjectExtension implements ExtensionInterface
8
8
{
9
9
public function load (array $ configs , ContainerBuilder $ configuration )
10
10
{
11
- $ config = call_user_func_array ('array_merge ' , $ configs );
11
+ $ configuration ->setParameter ('project.configs ' , $ configs );
12
+ $ configs = array_filter ($ configs );
13
+
14
+ if ($ configs ) {
15
+ $ config = call_user_func_array ('array_merge ' , $ configs );
16
+ } else {
17
+ $ config = array ();
18
+ }
12
19
13
20
$ configuration ->setDefinition ('project.service.bar ' , new Definition ('FooClass ' ));
14
21
$ configuration ->setParameter ('project.parameter.bar ' , isset ($ config ['foo ' ]) ? $ config ['foo ' ] : 'foobar ' );
Original file line number Diff line number Diff line change
1
+ project : ~
Original file line number Diff line number Diff line change @@ -207,6 +207,17 @@ public function testExtensions()
207
207
}
208
208
}
209
209
210
+ public function testExtensionWithNullConfig ()
211
+ {
212
+ $ container = new ContainerBuilder ();
213
+ $ container ->registerExtension (new \ProjectExtension ());
214
+ $ loader = new YamlFileLoader ($ container , new FileLocator (self ::$ fixturesPath .'/yaml ' ));
215
+ $ loader ->load ('null_config.yml ' );
216
+ $ container ->compile ();
217
+
218
+ $ this ->assertSame (array (null ), $ container ->getParameter ('project.configs ' ));
219
+ }
220
+
210
221
public function testSupports ()
211
222
{
212
223
$ loader = new YamlFileLoader (new ContainerBuilder (), new FileLocator ());
You can’t perform that action at this time.
0 commit comments