Skip to content
Merged
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
9 changes: 5 additions & 4 deletions console/calling_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ the returned code from the command (return value from command ``__invoke()``
method)::

// ...
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'app:create-user')]
class CreateUserCommand
{
public function __invoke(OutputInterface $output): int
public function __invoke(OutputInterface $output, Application $application): int
{
$greetInput = new ArrayInput([
// the command name is passed as first argument
Expand All @@ -37,7 +38,7 @@ method)::
// disable interactive behavior for the greet command
$greetInput->setInteractive(false);

$returnCode = $this->getApplication()->doRun($greetInput, $output);
$returnCode = $application->doRun($greetInput, $output);

// ...
}
Expand All @@ -54,8 +55,8 @@ method)::
Using ``doRun()`` instead of ``run()`` prevents autoexiting and allows to
return the exit code instead.

Also, using ``$this->getApplication()->doRun()`` instead of
``$this->getApplication()->find('demo:greet')->run()`` will allow proper
Also, using ``$application->doRun()`` instead of
``$application->find('demo:greet')->run()`` will allow proper
events to be dispatched for that inner command as well.

.. warning::
Expand Down