@@ -8,13 +8,13 @@ or if you want to create a "meta" command that runs a bunch of other commands
8
8
changed on the production servers: clearing the cache, generating Doctrine
9
9
proxies, dumping web assets, ...).
10
10
11
- Use the :method: `Symfony\\ Component\\ Console\\ Application::find ` method to
12
- find the command you want to run by passing the command name. Then, create a
13
- new :class: ` Symfony \\ Component \\ Console \\ Input \\ ArrayInput ` with the
14
- arguments and options you want to pass to the command .
11
+ Use the :method: `Symfony\\ Component\\ Console\\ Application::doRun `. Then, create
12
+ a new :class: ` Symfony \\ Component \\ Console \\ Input \\ ArrayInput ` with the
13
+ arguments and options you want to pass to the command. The command name must be
14
+ the first argument .
15
15
16
- Eventually, calling the ``run () `` method actually runs the command and returns
17
- the returned code from the command (return value from command's ``execute() ``
16
+ Eventually, calling the ``doRun () `` method actually runs the command and returns
17
+ the returned code from the command (return value from command ``execute() ``
18
18
method)::
19
19
20
20
// ...
@@ -29,15 +29,14 @@ method)::
29
29
30
30
protected function execute(InputInterface $input, OutputInterface $output): int
31
31
{
32
- $command = $this->getApplication()->find('demo:greet');
33
-
34
- $arguments = [
32
+ $greetInput = new ArrayInput([
33
+ // the command name is passed as first argument
34
+ 'command' => 'demo:greet',
35
35
'name' => 'Fabien',
36
36
'--yell' => true,
37
- ];
37
+ ]) ;
38
38
39
- $greetInput = new ArrayInput($arguments);
40
- $returnCode = $command->run($greetInput, $output);
39
+ $returnCode = $this->getApplication()->doRun($greetInput, $output);
41
40
42
41
// ...
43
42
}
@@ -47,7 +46,16 @@ method)::
47
46
48
47
If you want to suppress the output of the executed command, pass a
49
48
:class: `Symfony\\ Component\\ Console\\ Output\\ NullOutput ` as the second
50
- argument to ``$command->run() ``.
49
+ argument to ``$application->doRun() ``.
50
+
51
+ .. note ::
52
+
53
+ Using ``doRun() `` instead of ``run() `` prevents autoexiting and allows to
54
+ return the exit code instead.
55
+
56
+ Also, using ``$this->getApplication()->doRun() `` instead of
57
+ ``$this->getApplication()->find('demo:greet')->run() `` will allow proper
58
+ events to be dispatched for that inner command as well.
51
59
52
60
.. caution ::
53
61
0 commit comments