Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a caution note about invoking other commands #5425

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions components/console/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ method::
You can also test a whole console application by using
:class:`Symfony\\Component\\Console\\Tester\\ApplicationTester`.

.. _calling-existing-command:

Calling an Existing Command
---------------------------

Expand Down Expand Up @@ -505,16 +507,27 @@ Calling a command from another one is straightforward::
}

First, you :method:`Symfony\\Component\\Console\\Application::find` the
command you want to execute by passing the command name.

Then, you need to create a new
:class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments and
options you want to pass to the command.
command you want to execute by passing the command name. Then, you need to create
a new :class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments
and options you want to pass to the command.

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

.. tip::

If you want to suppress the output of the executed command, pass a
:class:`Symfony\\Component\\Console\\Output\\NullOutput` as the second
argument to ``$command->execute()``.

.. caution::

Note that all the commands will run in the same process and some of Symfony's
built-in commands may not work well this way. For instance, the ``cache:clear``
and ``cache:warmup`` commands change some class definitions, so running
something after them is likely to break.

.. note::

Most of the time, calling a command from code that is not executed on the
Expand Down
6 changes: 6 additions & 0 deletions cookbook/console/console_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ before translating contents::
However for other services the solution might be more complex. For more details,
see :doc:`/cookbook/service_container/scopes`.

Invoking other Commands
-----------------------

See :ref:`calling-existing-command` if you need to implement a command that runs
other dependent commands.

Testing Commands
----------------

Expand Down