public static function routeCommand(ConsoleApplication $console) { // TODO - currently in PHP it is impossible to make a constructor of a child class // have a constructor that has more restricted visibility than then parent class. // In an ideal world, ConsoleApplication would be a child class that does not have a // default constructor, as that would prevent 'accidental' insertion of an unitialized // object. // However that is not currently possible, and would require an RFC to change. //Figure out what Command was requested. try { $parsedCommand = $console->parseCommandLine(); } catch (\Exception $e) { //@TODO change to just catch parseException when that's implemented $output = new BufferedOutput(); $console->renderException($e, $output); echo $output->fetch(); exit(-1); } $output = $parsedCommand->getOutput(); $formatter = $output->getFormatter(); $formatter->setStyle('question', new OutputFormatterStyle('blue')); $formatter->setStyle('info', new OutputFormatterStyle('blue')); $questionHelper = new QuestionHelper(); $questionHelper->setHelperSet($console->getHelperSet()); $injectionParams = InjectionParams::fromParams($parsedCommand->getParams()); $executable = new Executable($parsedCommand->getCallable(), $injectionParams); $executable->setAllowedToReturnNull(true); return $executable; }
/** * */ public function execute() { //Figure out what Command was requested. try { $parsedCommand = $this->console->parseCommandLine(); } catch (ConfiguratorException $ce) { echo "Problem running configuration: " . $ce->getMessage(); exit(-1); } catch (\Exception $e) { //@TODO change to just catch parseException when that's implemented $output = new BufferedOutput(); $this->console->renderException($e, $output); echo $output->fetch(); exit(-1); } //Run the command requested, or the help callable if no command was input try { $output = $parsedCommand->getOutput(); $formatter = $output->getFormatter(); $formatter->setStyle('question', new OutputFormatterStyle('blue')); $formatter->setStyle('info', new OutputFormatterStyle('blue')); $questionHelper = new QuestionHelper(); $questionHelper->setHelperSet($this->console->getHelperSet()); // We currently have no config, so fine to create this directly. $injector = new Injector(); $injector->alias('Configurator\\Writer', 'Configurator\\Writer\\FileWriter'); $injector->defineParam('originalArgs', $this->originalArgs); foreach ($parsedCommand->getParams() as $key => $value) { $injector->defineParam($key, $value); } $injector->execute($parsedCommand->getCallable()); } catch (ConfiguratorException $ce) { echo "Error running task: \n"; echo $ce->getMessage(); exit(-1); } catch (\Exception $e) { echo "Unexpected exception of type " . get_class($e) . " running configurator`: " . $e->getMessage() . PHP_EOL; echo $e->getTraceAsString(); exit(-2); } }
public function testNoInteraction() { $dialog = new QuestionHelper(); $question = new Question('Do you have a job?', 'not yet'); $this->assertEquals('not yet', $dialog->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question)); }