Skip to content

Commit 5cf2616

Browse files
bug #62558 [DependencyInjection] Don't add empty .container.known_envs in XML loader (GromNaN)
This PR was merged into the 7.4 branch. Discussion ---------- [DependencyInjection] Don't add empty `.container.known_envs` in XML loader | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT The XML loader is the only one that creates the `.container.known_envs` parameter even if there is no `<when env="...">` in the file. The PHP and Yaml loaders read and update this parameter only when they find a `when@<env>` key. https://github.com/symfony/symfony/blob/1aa580f49841d479754c34102e42d334d0ce1a5a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php#L81-L85 https://github.com/symfony/symfony/blob/1aa580f49841d479754c34102e42d334d0ce1a5a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php#L958-L962 This is causing an issue in [symfony-config-xml-to-php](https://github.com/GromNaN/symfony-config-xml-to-php) when comparing the result of loading equivalent PHP and XML config files. This key is added by the XML loader, not the PHP loader. Commits ------- c3fa63b [DependencyInjection] Don't add the .container.known_envs parameter when empty
2 parents 3fc9d83 + c3fa63b commit 5cf2616

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ public function load(mixed $resource, ?string $type = null): mixed
6363
$this->loadXml($xml, $path, $root);
6464
}
6565
}
66-
$knownEnvs = $this->container->hasParameter('.container.known_envs') ? array_flip($this->container->getParameter('.container.known_envs')) : [];
6766
foreach ($xpath->query('//container:when') ?: [] as $root) {
68-
$knownEnvs[$root->getAttribute('env')] = true;
67+
$knownEnvs = $this->container->hasParameter('.container.known_envs') ? array_flip($this->container->getParameter('.container.known_envs')) : [];
68+
$this->container->setParameter('.container.known_envs', array_keys($knownEnvs + [$root->getAttribute('env') => true]));
6969
}
70-
$this->container->setParameter('.container.known_envs', array_keys($knownEnvs));
7170

7271
return null;
7372
}

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public function testLoadParameters()
154154
],
155155
'mixedcase' => ['MixedCaseKey' => 'value'],
156156
'constant' => \PHP_EOL,
157-
'.container.known_envs' => [],
158157
];
159158

160159
$this->assertEquals($expected, $actual, '->load() converts XML values to PHP ones');
@@ -191,7 +190,6 @@ public function testLoadImports()
191190
],
192191
'mixedcase' => ['MixedCaseKey' => 'value'],
193192
'constant' => \PHP_EOL,
194-
'.container.known_envs' => [],
195193
'bar' => '%foo%',
196194
'imported_from_ini' => true,
197195
'imported_from_yaml' => true,

0 commit comments

Comments
 (0)