Skip to content

Commit 8bd327f

Browse files
committed
Bind input before executing the COMMAND event
1 parent 58ed076 commit 8bd327f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Symfony/Component/Console/Application.php

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy