Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8bd327f

Browse filesBrowse files
committed
Bind input before executing the COMMAND event
1 parent 58ed076 commit 8bd327f
Copy full SHA for 8bd327f

File tree

2 files changed

+32
-0
lines changed
Filter options

2 files changed

+32
-0
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,10 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
880880
return $command->run($input, $output);
881881
}
882882

883+
// bind before the console.command event, so the listeners have access to input options/arguments
884+
$command->mergeApplicationDefinition();
885+
$input->bind($command->getDefinition());
886+
883887
$event = new ConsoleCommandEvent($command, $input, $output);
884888
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
885889

‎src/Symfony/Component/Console/Tests/ApplicationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,34 @@ public function testRunWithDispatcherSkippingCommand()
943943
$this->assertEquals(ConsoleCommandEvent::RETURN_CODE_DISABLED, $exitCode);
944944
}
945945

946+
public function testRunWithDispatcherAccessingInputOptions()
947+
{
948+
$noInteractionValue = null;
949+
$quietValue = null;
950+
951+
$dispatcher = $this->getDispatcher();
952+
$dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use (&$noInteractionValue, &$quietValue) {
953+
$input = $event->getInput();
954+
955+
$noInteractionValue = $input->getOption('no-interaction');
956+
$quietValue = $input->getOption('quiet');
957+
});
958+
959+
$application = new Application();
960+
$application->setDispatcher($dispatcher);
961+
$application->setAutoExit(false);
962+
963+
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
964+
$output->write('foo.');
965+
});
966+
967+
$tester = new ApplicationTester($application);
968+
$tester->run(array('command' => 'foo', '--no-interaction' => true));
969+
970+
$this->assertTrue($noInteractionValue);
971+
$this->assertFalse($quietValue);
972+
}
973+
946974
public function testTerminalDimensions()
947975
{
948976
$application = new Application();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.