-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection][Routing] Access environment in PHP config #40808
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for you to have a ->when('test')
method as well? Like we recently did for ContainerConfigurator
.
I will actually work on remove the I like it in yaml and XML because it allows me to write simple logic, however, in PHP I do not need a feature to "help me with simple logic". |
I was thinking about this config based on your example: use Symfony\Config\FrameworkConfig;
return static function (FrameworkConfig $framework)
{
$framework->when('test')
->test(true)
->session()->storageFactoryId('session.storage.mock_file')
;
}; Not sure if possible though (I didn't check if the generated Config is fluent). |
Yes, That is the alternative way of doing things. The implementation is more difficult and it is less obvious what is happening. |
Sorry for opening the PR too early. I would be super happy to get your review later
Hm.. So we are loading callbacks on 4 places.
For 2, we have a fancy resolver of the parameters. So order does not matter, but parameter name does. For the others, order does matter but not parameter name. The fancy resolver is needed for the ConfigBuilders. I would like to use fancy resolving for all of these, but either I write (almost) the same code on 3 more places or I try to do something complex... |
string $env
in PhpFileLoader
So, instead of doing fancy argument resolving on all places. I added I've updated the description. This PR is ready for a review. |
src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php
Outdated
Show resolved
Hide resolved
Thank you @Nyholm. |
Woho. Let's start write php config |
This will allow me to write config like:
This PR will also revert parts of #40214. It is much simpler to maintain and write PHP config without
->when()
. Instead we addContainerConfigurator::env(): ?string
andRoutingConfigurator::env(): ?string
.