@@ -18,14 +18,15 @@ the returned code from the command (return value from command ``__invoke()``
1818method)::
1919
2020 // ...
21+ use Symfony\Component\Console\Application;
2122 use Symfony\Component\Console\Attribute\AsCommand;
2223 use Symfony\Component\Console\Input\ArrayInput;
2324 use Symfony\Component\Console\Output\OutputInterface;
2425
2526 #[AsCommand(name: 'app:create-user')]
2627 class CreateUserCommand
2728 {
28- public function __invoke(OutputInterface $output): int
29+ public function __invoke(OutputInterface $output, Application $application ): int
2930 {
3031 $greetInput = new ArrayInput([
3132 // the command name is passed as first argument
@@ -37,7 +38,7 @@ method)::
3738 // disable interactive behavior for the greet command
3839 $greetInput->setInteractive(false);
3940
40- $returnCode = $this->getApplication() ->doRun($greetInput, $output);
41+ $returnCode = $application ->doRun($greetInput, $output);
4142
4243 // ...
4344 }
@@ -54,8 +55,8 @@ method)::
5455 Using ``doRun() `` instead of ``run() `` prevents autoexiting and allows to
5556 return the exit code instead.
5657
57- Also, using ``$this->getApplication() ->doRun() `` instead of
58- ``$this->getApplication() ->find('demo:greet')->run() `` will allow proper
58+ Also, using ``$application ->doRun() `` instead of
59+ ``$application ->find('demo:greet')->run() `` will allow proper
5960 events to be dispatched for that inner command as well.
6061
6162.. warning ::
0 commit comments