@@ -18,14 +18,15 @@ the returned code from the command (return value from command ``__invoke()``
18
18
method)::
19
19
20
20
// ...
21
+ use Symfony\Component\Console\Application;
21
22
use Symfony\Component\Console\Attribute\AsCommand;
22
23
use Symfony\Component\Console\Input\ArrayInput;
23
24
use Symfony\Component\Console\Output\OutputInterface;
24
25
25
26
#[AsCommand(name: 'app:create-user')]
26
27
class CreateUserCommand
27
28
{
28
- public function __invoke(OutputInterface $output): int
29
+ public function __invoke(OutputInterface $output, Application $application ): int
29
30
{
30
31
$greetInput = new ArrayInput([
31
32
// the command name is passed as first argument
@@ -37,7 +38,7 @@ method)::
37
38
// disable interactive behavior for the greet command
38
39
$greetInput->setInteractive(false);
39
40
40
- $returnCode = $this->getApplication() ->doRun($greetInput, $output);
41
+ $returnCode = $application ->doRun($greetInput, $output);
41
42
42
43
// ...
43
44
}
@@ -54,8 +55,8 @@ method)::
54
55
Using ``doRun() `` instead of ``run() `` prevents autoexiting and allows to
55
56
return the exit code instead.
56
57
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
59
60
events to be dispatched for that inner command as well.
60
61
61
62
.. warning ::
0 commit comments