Skip to content

Commit b86ffb6

Browse files
javiereguiluzweaverryan
authored andcommitted
Removed duplication and moved a caution message
1 parent 57938a5 commit b86ffb6

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

components/console/introduction.rst

+17-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,26 @@ 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 :class:`Symfony\\Component\\Console\\Output\\NullOutput`
494+
as the second argument to ``$command->execute()``.
495+
496+
.. caution::
497+
498+
Note that all the commands will run in the same process, and some of Symfony's
499+
built-in commands may not work well this way. For instance, ``cache:clear``
500+
and ``cache:warmup`` commands change some class definitions, so running something
501+
after them is likely to break.
502+
491503
.. note::
492504

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

cookbook/console/console_command.rst

+2-30
Original file line numberDiff line numberDiff line change
@@ -153,36 +153,8 @@ see :doc:`/cookbook/service_container/scopes`.
153153
Invoking Other Commands
154154
-----------------------
155155

156-
If you need to implement a command that runs other dependent commands, you can fetch
157-
these commands using the :class:`Symfony\\Component\\Console\\Application <Symfony\\Component\\Console\\Application>`'s ``find`` method.
158-
159-
Also note that you'll have to pass :class:`Symfony\\Component\\Console\\Input\\InputInterface` and :class:`Symfony\\Component\\Console\\Output\\OutputInterface`
160-
as arguments to the command's ``execute`` method. This can be easily implemented
161-
with :class:`Symfony\\Component\\Console\\Input\\ArrayInput`::
162-
163-
protected function execute(InputInterface $input, OutputInterface $output)
164-
{
165-
$command = $this->getApplication()->find('some:command');
166-
$command->execute(
167-
new ArrayInput(array(
168-
'foo' => 'foo',
169-
'--bar' => 'foobar',
170-
)),
171-
$output
172-
);
173-
}
174-
175-
.. tip::
176-
177-
If you want to suppress the output of the executed command, pass a :class:`Symfony\\Component\\Console\\Output\\NullOutput`
178-
as the second argument to ``$command->execute()``.
179-
180-
.. caution::
181-
182-
Note that all these commands will run in the same process, and some of Symfony's
183-
built-in commands may not work well this way. For instance, ``cache:clear`` and ``cache:warmup``
184-
commands change some class definitions, so running something
185-
after them is likely to break.
156+
See :ref:`calling-existing-command` if you need to implement a command that runs
157+
other dependent commands.
186158

187159
Testing Commands
188160
----------------

0 commit comments

Comments
 (0)