Skip to content

Commit 2e290a7

Browse files
committed
Merge branch '4.0'
* 4.0: [HttpFoundation] Use the correct syntax for session gc based on Pdo driver Removed assertDateTimeEquals() methods. Revert "bug #24987 [Console] Fix global console flag when used in chain (Simperfit)" Revert "bug #25487 [Console] Fix a bug when passing a letter that could be an alias (Simperfit)" Disable CSP header on exception pages only in debug Fixed submitting disabled buttons Fixed Button::setParent() when already submitted Improve assertions Restore RoleInterface import [Console] Provide a bugfix where an array could be passed Improve assertions SCA: get rid of repetitive calls allow null values for root nodes in YAML configs revert useless tests fixtures changes [VarDumper] Fix docblock Improve phpdoc to make it more explicit [DI] Fix initialization of legacy containers by delaying include_once
2 parents 06671a9 + d68cfbe commit 2e290a7

File tree

8 files changed

+44
-10
lines changed

8 files changed

+44
-10
lines changed

Container.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ public function setParameter($name, $value)
142142
*/
143143
public function set($id, $service)
144144
{
145+
// Runs the internal initializer; used by the dumped container to include always-needed files
146+
if (isset($this->privates['service_container']) && $this->privates['service_container'] instanceof \Closure) {
147+
$initialize = $this->privates['service_container'];
148+
unset($this->privates['service_container']);
149+
$initialize();
150+
}
151+
152+
$id = $this->normalizeId($id);
153+
145154
if ('service_container' === $id) {
146155
throw new InvalidArgumentException('You cannot set service "service_container".');
147156
}

ContainerBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,16 @@ public function fileExists(string $path, $trackContents = true): bool
402402
* @throws BadMethodCallException When this ContainerBuilder is compiled
403403
* @throws \LogicException if the extension is not registered
404404
*/
405-
public function loadFromExtension($extension, array $values = array())
405+
public function loadFromExtension($extension, array $values = null)
406406
{
407407
if ($this->isCompiled()) {
408408
throw new BadMethodCallException('Cannot load from an extension on a compiled container.');
409409
}
410410

411+
if (func_num_args() < 2) {
412+
$values = array();
413+
}
414+
411415
$namespace = $this->getExtension($extension)->getAlias();
412416

413417
$this->extensionConfigs[$namespace][] = $values;

Dumper/PhpDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,16 +1096,16 @@ private function addInlineRequires(): string
10961096
}
10971097
}
10981098

1099-
$code = "\n";
1099+
$code = '';
11001100

11011101
foreach ($lineage as $file) {
11021102
if (!isset($this->inlinedRequires[$file])) {
11031103
$this->inlinedRequires[$file] = true;
1104-
$code .= sprintf(" include_once %s;\n", $file);
1104+
$code .= sprintf("\n include_once %s;", $file);
11051105
}
11061106
}
11071107

1108-
return "\n" === $code ? '' : $code;
1108+
return $code ? sprintf("\n \$this->privates['service_container'] = function () {%s\n };\n", $code) : '';
11091109
}
11101110

11111111
private function addDefaultParametersMethod(): string

Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ private function loadFromExtensions(array $content)
768768
continue;
769769
}
770770

771-
if (!is_array($values)) {
771+
if (!is_array($values) && null !== $values) {
772772
$values = array();
773773
}
774774

Tests/Fixtures/includes/ProjectExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ class ProjectExtension implements ExtensionInterface
88
{
99
public function load(array $configs, ContainerBuilder $configuration)
1010
{
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+
}
1219

1320
$configuration->register('project.service.bar', 'FooClass')->setPublic(true);
1421
$configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');

Tests/Fixtures/php/services_inline_requires.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ public function __construct()
4141

4242
$this->aliases = array();
4343

44-
include_once $this->targetDirs[1].'/includes/HotPath/I1.php';
45-
include_once $this->targetDirs[1].'/includes/HotPath/P1.php';
46-
include_once $this->targetDirs[1].'/includes/HotPath/T1.php';
47-
include_once $this->targetDirs[1].'/includes/HotPath/C1.php';
44+
$this->privates['service_container'] = function () {
45+
include_once $this->targetDirs[1].'/includes/HotPath/I1.php';
46+
include_once $this->targetDirs[1].'/includes/HotPath/P1.php';
47+
include_once $this->targetDirs[1].'/includes/HotPath/T1.php';
48+
include_once $this->targetDirs[1].'/includes/HotPath/C1.php';
49+
};
4850
}
4951

5052
public function reset()

Tests/Fixtures/yaml/null_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
project: ~

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ public function testExtensions()
221221
}
222222
}
223223

224+
public function testExtensionWithNullConfig()
225+
{
226+
$container = new ContainerBuilder();
227+
$container->registerExtension(new \ProjectExtension());
228+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
229+
$loader->load('null_config.yml');
230+
$container->compile();
231+
232+
$this->assertSame(array(null), $container->getParameter('project.configs'));
233+
}
234+
224235
public function testSupports()
225236
{
226237
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator());

0 commit comments

Comments
 (0)