Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DependencyInjection] Process PHP configs using the ContainerConfigurator #54970

Merged
merged 1 commit into from
May 17, 2024

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented May 17, 2024

Q A
Branch? 7.1
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #54852
License MIT

Since #52843, ContainerConfigurator::extension is not called anymore which means ParamConfigurators are no longer processed and converted to strings, and makes nodes validation fail: e.g. framework.secret would receive an EnvConfigurator and throw because it is not a scalar.

@nicolas-grekas
Copy link
Member

Thank you @MatTheCat.

@nicolas-grekas nicolas-grekas merged commit 4e01371 into symfony:7.1 May 17, 2024
3 of 10 checks passed
@MatTheCat
Copy link
Contributor Author

…that was fast!

@yceruto does this PR seem okay to you?

@MatTheCat MatTheCat deleted the ticket_54852 branch May 17, 2024 14:29
foreach ($configBuilders as $configBuilder) {
$this->loadExtensionConfig($configBuilder->getExtensionAlias(), $configBuilder->toArray());
$containerConfigurator->extension($configBuilder->getExtensionAlias(), $configBuilder->toArray(), $this->prepend);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to do some config prepending tests, but I feel that we've missed something here as the previous $this->loadExtensionConfig() is currently doing more things when prepend argument is true, e.g. the nested importing might be broken...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you made the ContainerConfigurator able to prepend in #52636 so I assumed it was okay but it is indeed missing this part:

if ($this->importing) {
if (!isset($this->extensionConfigs[$namespace])) {
$this->extensionConfigs[$namespace] = [];
}
array_unshift($this->extensionConfigs[$namespace], $config);
return;
}

Don’t know if it is an issue at all though 😓

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it'll be an issue when want to prepend nested configs using imports

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some quick tests, the root issue should be mitigated by processing only the config value this way:

$this->loadExtensionConfig($configBuilder->getExtensionAlias(), ContainerConfigurator::processValue($configBuilder->toArray()));

that will keep the prepending strategy working again. Would you mind creating another PR to update it? I can do it otherwise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you already have the tests I think you’re more reading than I am; go ahead 😁

Would ContainerConfiguration::extension serve a purpose then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would ContainerConfiguration::extension serve a purpose then?

It should be avoided internally where recursive importing is involved, as now importing from prependExtension() is supported (which requires an specific holding strategy to keep the importing order). However, you can still use it on your end for trivial array config importing (either in the prependExtension() or loadExtension() methods).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okaaay thanks; glad I asked your review 😄

@yceruto
Copy link
Member

yceruto commented May 17, 2024

@MatTheCat thanks for the ping, I'm checking deeper... but AFAIR we don't resolve env var during prepending phase before, it's done during the merging process (aka loadExtension) when all configs were merged.

@MatTheCat
Copy link
Contributor Author

@yceruto thanks for looking!

Not sure what you call “resolving” env vars but this PR essentially stringify ParamConfigurators, which happens before replacing said parameters with their actual value.

@yceruto
Copy link
Member

yceruto commented May 17, 2024

but AFAIR we don't resolve env var during prepending phase before, it's done during the merging process (aka loadExtension) when all configs were merged.

Nevemind, I got it, it's about processing the configurator as before https://github.com/symfony/symfony/pull/52843/files#diff-1cd56b329433fc34d950d6eeab9600752aa84a76cbe0693d3fab57fed0f547d3L150

@fabpot fabpot mentioned this pull request May 17, 2024
fabpot added a commit that referenced this pull request May 21, 2024
…ig loader (yceruto)

This PR was merged into the 7.1 branch.

Discussion
----------

[DependencyInjection] Fix prepending strategy for php config loader

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54852
| License       | MIT

working towards fixing #54970

Commits
-------

a7ecb85 Fix prepending strategy for php config loader
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request May 21, 2024
…ig loader (yceruto)

This PR was merged into the 7.1 branch.

Discussion
----------

[DependencyInjection] Fix prepending strategy for php config loader

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54852
| License       | MIT

working towards fixing symfony/symfony#54970

Commits
-------

a7ecb8568d Fix prepending strategy for php config loader
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.

[Config] ParamConfigurator is not longer respected as scalar-string-value
4 participants