Description
Description
Hello, recently i've became the Crunz maintainer, after some review i've realized that Crunz doesn't use DI container - this means static calls and no way to write sensible test. In the meantime @TomasVotruba published some blog posts about adding DI container to CLI apps, as you can see there is no standard/recommended way to add DI to CLI app.
One approach is to copy some code from HttpKernel
as i do in Crunz , but maintaining it is not nice nor easy. Nobody wants to reinvent the wheel.
Another approach, as suggested in above blog post, is to use Kernel
provded by http-kernel
package but i do not like this idea because it is weird to have full http support in CLI app :)
IMO there are three ways to increase DX and easy development of CLI apps with DI container:
- Introduce something like "cli-kernel" - like
http-kernel
(andframework-bundle
) but for CLI. IMO this is the best way because developers can also have other features, out-of-the-box, likeautoconfigure
Symfony commands, easy access to container in test env and many others. - Extend
Symfony\Component\Console\Application
to support DI natively. For example by decorator. - Improve docs :) If you think that above options aren't good it would be very nice to at least add recommended way to glue
DI
andConsole
.
What do you think?
Thanks.