protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
$helperSet = $command->getHelperSet();
foreach ($helperSet as $helper) {
if ($helper instanceof OutputAwareInterface) {
$helper->setOutput($output);
}
if ($helper instanceof InputAwareInterface) {
$helper->setInput($input);
}
}
$event = new ConsoleCommandEvent($command, $input, $output);
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
try {
$exitCode = $command->run($input, $output);
} catch (\Exception $e) {
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
if ($e instanceof UserException) {
$this->getHelperSet()->get('gush_style')->error($e->getMessages());
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
throw $e;
}
return $event->getExitCode();
} else {
throw $event->getException();
}
}
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
return $event->getExitCode();
}