Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | yes |
Symfony version | 4.0.0 |
Recently symfony added two great features - lazy console commands and service autoconfiguration.
Correct me if I'm wrong but I don't think these two work together very well now. If I add a command and setup autoconfiguration like this:
services:
_defaults:
autowire: true
autoconfigure: true
App\Console\FooCommand: ~
$container
->registerForAutoconfiguration(Command::class)
->addTag('console.command');
then the command won't be lazy because the command attribute is missing in the tag, right? And there is no way to fix this at the moment as far as I know without adding the tag manually in yaml.
This applies for many other cases where some details need to be added to the service tags - the tags need to be added manually even though it could theoretically be solved with some custom magic.
For example commands could be solved with something like this:
$container
->registerForAutoconfiguration(Command::class)
->addCallback(
function (Definition $definition) {
$command = new $definition->getClass();
// Or `ReflectionClass::newInstanceWithoutConstructor` to allow constructor injection.
$definition->addTag('console.command', ['command' => $command->getName()])
}
);
Could something like this be added to Symfony 4.1? I'm only talking about the autoconfiguration callback feature, not the magic for commands - that's just an example to demonstrate a use-case.
I can try to send a PR if such feature is wanted in Symfony. But I need some advice with what the API should look like as I'm not that familiar with DependencyInjection component internals.