I'm moving an InvokableServiceCommand to a bundle, and am stuck on how to inject the container, which happens automatically if it's in the application.
class SurvosApiGridBundle extends AbstractBundle
{
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$definition = $builder->autowire(ApiIndexCommand::class)
->setArgument('$entityManager', new Reference('doctrine.orm.entity_manager'))
->setArgument('$bag', new Reference('parameter_bag'))
->setArgument('$serializer', new Reference('serializer'))
->addTag('console.command')
;
This throws the error:
In DefinitionErrorExceptionPass.php line 51:
Cannot autowire service "Survos\ApiGrid\Command\ApiIndexCommand": argument "$container" of method "Zenstruck\Console\InvokableServiceCommand::setInvokeContainer()" references interface "Psr\Container\ContainerInterface" but no such service exists. Did you mean to target "parameter_bag" instead?
I'm moving an InvokableServiceCommand to a bundle, and am stuck on how to inject the container, which happens automatically if it's in the application.
This throws the error:
In DefinitionErrorExceptionPass.php line 51:
Cannot autowire service "Survos\ApiGrid\Command\ApiIndexCommand": argument "$container" of method "Zenstruck\Console\InvokableServiceCommand::setInvokeContainer()" references interface "Psr\Container\ContainerInterface" but no such service exists. Did you mean to target "parameter_bag" instead?
So I tried to add a method call
But obviously this doesn't work, the $container is a ContainerConfigurator object.
So then I thought it belongs in the compiler pass, but got stuck.
How do I set up an InvokableServiceCommand from within a bundle?
Thanks!