8000 [DependencyInjection] Don't add empty `.container.known_envs` in XML loader by GromNaN · Pull Request #62558 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@GromNaN
Copy link
Member
@GromNaN GromNaN commented Nov 28, 2025
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.

if (str_starts_with($namespace, 'when@')) {
$knownEnvs = $this->container->hasParameter('.container.known_envs') ? array_flip($this->container->getParameter('.container.known_envs')) : [];
$this->container->setParameter('.container.known_envs', array_keys($knownEnvs + [substr($namespace, 5) => true]));
continue;
}

if (str_starts_with($namespace, 'when@')) {
$knownEnvs = $this->container->hasParameter('.container.known_envs') ? array_flip($this->container->getParameter('.container.known_envs')) : [];
$this->container->setParameter('.container.known_envs', array_keys($knownEnvs + [substr($namespace, 5) => true]));
continue;
}

This is causing an issue in 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.

@carsonbot carsonbot added this to the 7.4 milestone Nov 28, 2025
@carsonbot carsonbot changed the title [DependencyInjection] Don't add .container.known_envs when empty [DependencyInjection] Don't add .container.known_envs when empty Nov 28, 2025
@GromNaN GromNaN changed the title [DependencyInjection] Don't add .container.known_envs when empty [DependencyInjection] Don't add .container.known_envs when empty in XML loader Nov 28, 2025
…hen empty

Other loaders does not create this parameter when there is no when@<env> key
@GromNaN GromNaN changed the title [DependencyInjection] Don't add .container.known_envs when empty in XML loader [DependencyInjection] Don't add empty .container.known_envs in XML loader Nov 28, 2025
@nicolas-grekas
Copy link
Member

Thank you @GromNaN.

@nicolas-grekas nicolas-grekas merged commit 5cf2616 into symfony:7.4 Dec 1, 2025
5 of 12 checks passed
@GromNaN GromNaN deleted the di-known-env branch December 1, 2025 20:34
GromNaN added a commit to GromNaN/symfony-config-xml-to-php that referenced this pull request Dec 2, 2025
GromNaN added a commit to GromNaN/symfony-config-xml-to-php that referenced this pull request Dec 2, 2025
GromNaN added a commit to GromNaN/symfony-config-xml-to-php that referenced this pull request Dec 2, 2025
This was referenced Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0