-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC] [DependencyInjection] Custom container configurators (fluent PHP format) #25630
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
Comments
Though I really like the idea, won't this be double bookkeeping with the configuration nodes? |
Maybe then we can deprecate the configuration |
I think you can already achieve what you want very easily: return function (ContainerConfigurator $c) {
$myBundle = new MyBundleConfigurator($c);
$myBundle->setWhatever();
} Nothing required from core. WDYT? |
I think it's possible that bundle might want to inject some additional dependencies/parameters. |
There is no violation of DRY if I understand your point correctly. Configuration nodes is attempt to make abstraction layer over all formats, but even in the current state it is leaky abstraction (e.g. there is By the way, XML schema is sort of "double bookkeeping" as well if you want. |
Fixed by #27065? |
How do I type hint against I see |
Maybe you could extend a base class that would provide the logic? |
Oh, I see, technically it would work. It's just matter of taste I guess. Anonymous class with Still, I'd implement that feature (#25650) as well, but it's up to you. |
…P-DSL loaders (aurimasniekis) This PR was squashed before being merged into the 4.1-dev branch (closes #27065). Discussion ---------- [DI][Routing] Allow invokable objects to be used as PHP-DSL loaders | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26583, #25630 | License | MIT | Doc PR | none Changed DI/Router PHPFileLoader to check is_object && is_callable instead of instance of Closure Commits ------- 662ff7e [DI][Routing] Allow invokable objects to be used as PHP-DSL loaders
So far we have extensions for custom and simplified configurations, e.g.
which is fine in many cases, but it doesn't use all capabilities of PHP. I'd be happy to have native custom configurator like the following, for example:
I see at least 3 benefits:
It allows provide self-descriptive configurators, simplifies learning DSL of the extension (by playing with autocomplete options).
Such configurators prevent many typos because we work with methods, not custom arrays. So far only XML has self-validation, but this format is painful for many people.
It helps to introduce your own DSL in your project (e.g. I can add
->anonymous()
helper like I suggested in [DependencyInjection] Anonymous services in PHP DSL #24632). @nicolas-grekas mentioned it as possible solution for me:Unfortunately, Symfony doesn't support it out-of-box.
The idea is simple: bundle/extension should be able to register it's own container configurator factory:
Then we can detect closure argument type and inject appropriate container configurator.
The text was updated successfully, but these errors were encountered: