-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Lazy commands and callInjects #54
Comments
Hi @MartinMystikJonas. Why do you need that functionality? I mean, command can be autowired via constructor and it's lazily created. |
Parent class Command constructor already uses some parameters so I preffer not to mess up with that in my code to avoid incompatibilities. Imho injects are better solution here and I would prefer them over overiding constructor. So I think this could be an useful option. |
Or maybe just give us option to choose CommandLoader class via config. Currently it is not easy to use different loader by just redefining service because of command map parameter. |
That's nonsence. Just call the parent constructor with no arguments and specify command in |
Ok. So I can be sure that redefining constructor signature will be ok. Fine. Yet maybe support for custom command loader could be useful sometimes. |
I am ok to support other command loader, but I can't imagine any other, can you prepare PR with your idea? |
I will |
I started working on it and I have few questions about what approach select:
or allow lazy option to pass class (false = not lazy, true = default loader, class = use specific loader)
|
Hi @MartinMystikJonas, is it still relevant? |
I use this workaround in our apps: class Command extends \Symfony\Component\Console\Command\Command {
public function setApplication(Application $application = null): void {
parent::setApplication($application);
if($application) {
/** @var ContainerHelper $container */
$container = $this->getHelper('container');
$container->callInjects($this);
}
}
} And it works just fine. So if nobody else is interested in this feature I can live with this custom solution. |
What is your motivation? Why don't you use constructor? |
Pure laziness :-) |
I see. Lets make it. Prepare PR my padawan. |
I am trying this as replacement for Kdyby/Console and I had idea of small improvement. What about use container callInjects when lazy loading commands by CommandLoader. Commands then would behave similar to presenters. Creazed when needed with required dependencies autimatically injected. It would provide easy way to get dependencies without helpers. What do you think? Should I prepare PR?
The text was updated successfully, but these errors were encountered: