-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Suggestion for autowiring parameters #22755
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
Something similar was proposed in #20738 and rejected in favor of the current argument binding by name. |
@jvasseur Thank you, didn't see it before. I am guessing doing something like this (the <?php
class RecipeLoader
{
/**
* @param LoggerInterface $logger
* @param bool $kernelDebugParameter %kernel.debug%
*/
public function __construct(LoggerInterface $logger, $kernelDebugParameter)
{
//...
}
} has also been rejected? A bit offtopic: I still like the idea of autowiring params and tried to understand the code in Symfony\Component\DependencyInjection\Compiler\AutowirePass. It is complicated but I think I could figure it. So before I try to make a bundle to do that, can you tell me if it is even possible? I am not looking for help but given I am not S3 expert, I would just like to know if it is even possible to do. |
Hey! Yea, it's certainly possible, but I don't think a proposal like this will be accepted into core, at least not for a little while: we need to see how these things work in the wild. And so far, autowiring is very non-magic: it relies on type-hints only. I also proposed a PR that used annotations to wire arguments, but it was rejected. Another option - especially to serve as a proof of concept - is to create a bundle and do this there. You would not be able to use AutowirePass, you'd create your own compiler pass that looked at missing arguments to autowired methods and check the docs or whatever you want. Itams non-trivial in large part due to parent child definition stuff (that's what the AbstractRecursivePass relates to), but doable. Also, your pass wouldn't need to worry about the "types" in the container, so that also simplifies things. So that's my advice for now: try it in a bundle. Then of course, you can always submit a PR here - the temperament for a feature may or may not change in the future. We don't want to add things that really look magic :) |
Thanks @weaverryan , I will surely do try. I watched your presentation of symfony flex and like how services are auto-registered and tagged with no yml definition (twig extension thing). Being able to autowire parameters would be even better. |
What do you think about making this per-config optional? Like |
When services are autowired, parameter values still needs to be declared in definition like:
What about guessing them based on variable name? For example:
So if variable ends with word
parameter
, S3 would tableizeclientHost
, look for parameterclient_host
and inject it.An example taken from Symfony Flex demo would then become:
What do you think?
Sorry if someone posted this idea before.
The text was updated successfully, but these errors were encountered: