[Bundles] [Bundle] Fix code example about prepend config #16808
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See issue symfony/symfony#40198
The prepend mechanism happens before resolving any parameters and env vars, so at this moment the raw configs are not yet ready to be normalized and merged.
Note that you can prepend a raw config like this one without any problem:
Now, if you want to add an extension config based on another extension config, what you have to do is to prepend this config iterating over the other one without merging, e.g.:
Where
$config['enabled']
can be a boolean value, a parameter, or an env var. It doesn't matter because the real value will be determined by Symfony after resolving, normalizing, and merging all configs.Note also that you can't be 100% sure that
$container->getExtensionConfig('foo')
will return all configs because there could be another extension (being executed after) appending config to your ownfoo
extension, and then the final config could differ.About conditional configuration, it's harder to handle here. Even if you can resolve the parameter or env var to know the real value you should never pass the resolved value to another config, otherwise, something like this symfony/symfony#40198 (comment) will happen, especially when env vars are used.
Therefore, the current documentation is error-prone as is, so I suggest using the iteration approach instead to avoid any issue with parameters and env vars.