Example #1
0
 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;
 }
Example #2
0
 /**
  * Sets the application instance for this command.
  *
  * @param Application $application An Application instance
  *
  * @api
  */
 public function setApplication(Application $application = null)
 {
     $this->application = $application;
     if ($application) {
         $this->setHelperSet($application->getHelperSet());
     } else {
         $this->helperSet = null;
     }
 }
Example #3
0
 public function testAddingSingleHelperSetOverwritesDefaultValues()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $application->setHelperSet(new HelperSet(array(new FormatterHelper())));
     $helperSet = $application->getHelperSet();
     $this->assertTrue($helperSet->has('formatter'));
     // no other default helper set should be returned
     $this->assertFalse($helperSet->has('dialog'));
     $this->assertFalse($helperSet->has('progress'));
 }