Skip to content

Commit 7d1f764

Browse files
committed
minor #5425 Added a caution note about invoking other commands (kix, javiereguiluz)
This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #5425). Discussion ---------- Added a caution note about invoking other commands | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | all | Fixed tickets | - This PR finishes #4493. That's why is committed against `master` branch, but it should be merged in 2.3+. Commits ------- 2c491be Fixed typos b86ffb6 Removed duplication and moved a caution message 57938a5 [Console] Added a cookbook entry on invoking other commands
2 parents eb1ee92 + 2c491be commit 7d1f764

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

components/console/introduction.rst

+18-5
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ method::
449449
You can also test a whole console application by using
450450
:class:`Symfony\\Component\\Console\\Tester\\ApplicationTester`.
451451

452+
.. _calling-existing-command:
453+
452454
Calling an Existing Command
453455
---------------------------
454456

@@ -478,16 +480,27 @@ Calling a command from another one is straightforward::
478480
}
479481

480482
First, you :method:`Symfony\\Component\\Console\\Application::find` the
481-
command you want to execute by passing the command name.
482-
483-
Then, you need to create a new
484-
:class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments and
485-
options you want to pass to the command.
483+
command you want to execute by passing the command name. Then, you need to create
484+
a new :class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments
485+
and options you want to pass to the command.
486486

487487
Eventually, calling the ``run()`` method actually executes the command and
488488
returns the returned code from the command (return value from command's
489489
``execute()`` method).
490490

491+
.. tip::
492+
493+
If you want to suppress the output of the executed command, pass a
494+
:class:`Symfony\\Component\\Console\\Output\\NullOutput` as the second
495+
argument to ``$command->execute()``.
496+
497+
.. caution::
498+
499+
Note that all the commands will run in the same process and some of Symfony's
500+
built-in commands may not work well this way. For instance, the ``cache:clear``
501+
and ``cache:warmup`` commands change some class definitions, so running
502+
something after them is likely to break.
503+
491504
.. note::
492505

493506
Most of the time, calling a command from code that is not executed on the

cookbook/console/console_command.rst

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ before translating contents::
150150
However for other services the solution might be more complex. For more details,
151151
see :doc:`/cookbook/service_container/scopes`.
152152

153+
Invoking other Commands
154+
-----------------------
155+
156+
See :ref:`calling-existing-command` if you need to implement a command that runs
157+
other dependent commands.
158+
153159
Testing Commands
154160
----------------
155161

0 commit comments

Comments
 (0)