Exemple #1
0
 /**
  * Prompts the user to answer a question
  *
  * @param IQuestion $question The question to ask
  * @param IResponse $response The response to write output to
  * @return mixed The user's answer to the question
  * @throws RuntimeException Thrown if we failed to get the user's answer
  */
 public function ask(IQuestion $question, IResponse $response)
 {
     $response->write("<question>{$question->getText()}</question>");
     if ($question instanceof MultipleChoice) {
         /** @var MultipleChoice $question */
         $response->writeln("");
         $choicesAreAssociative = $question->choicesAreAssociative();
         $choiceTexts = [];
         foreach ($question->getChoices() as $key => $choice) {
             if (!$choicesAreAssociative) {
                 // Make the choice 1-indexed
                 $key += 1;
             }
             $choiceTexts[] = [$key . ")", $choice];
         }
         $response->writeln($this->paddingFormatter->format($choiceTexts, function ($row) {
             return "  {$row[0]} {$row[1]}";
         }));
         $response->write($question->getAnswerLineString());
     }
     $answer = fgets($this->inputStream, 4096);
     if ($answer === false) {
         throw new RuntimeException("Failed to get answer");
     }
     $answer = trim($answer);
     if (mb_strlen($answer) == 0) {
         $answer = $question->getDefaultAnswer();
     }
     return $question->formatAnswer($answer);
 }
 /**
  * @inheritdoc
  */
 protected function doExecute(IResponse $response)
 {
     $response->write($this->executable->update());
     $this->commandCollection->call("composer:dump-autoload", $response);
 }
 /**
  * @inheritdoc
  */
 protected function doExecute(IResponse $response)
 {
     $response->write($this->executable->dumpAutoload("-o"));
 }