當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Question::getDefault方法代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Question\Question::getDefault方法的典型用法代碼示例。如果您正苦於以下問題:PHP Question::getDefault方法的具體用法?PHP Question::getDefault怎麽用?PHP Question::getDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Console\Question\Question的用法示例。


在下文中一共展示了Question::getDefault方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: writePrompt

 /**
  * {@inheritdoc}
  */
 protected function writePrompt(OutputInterface $output, Question $question)
 {
     $text = $question->getQuestion();
     $default = $question->getDefault();
     switch (true) {
         case null === $default:
             $text = sprintf(' <info>%s</info>:', $text);
             break;
         case $question instanceof ConfirmationQuestion:
             $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
             break;
         case $question instanceof ChoiceQuestion && $question->isMultiSelect():
             $choices = $question->getChoices();
             $default = explode(',', $default);
             foreach ($default as $key => $value) {
                 $default[$key] = $choices[trim($value)];
             }
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, implode(', ', $default));
             break;
         case $question instanceof ChoiceQuestion:
             $choices = $question->getChoices();
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
             break;
         default:
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $default);
     }
     $output->writeln($text);
     if ($question instanceof ChoiceQuestion) {
         $width = max(array_map('strlen', array_keys($question->getChoices())));
         foreach ($question->getChoices() as $key => $value) {
             $output->writeln(sprintf("  [<comment>%-{$width}s</comment>] %s", $key, $value));
         }
     }
     $output->write(' > ');
 }
開發者ID:aaronleslie,項目名稱:aaronunix,代碼行數:38,代碼來源:SymfonyQuestionHelper.php

示例2: writePrompt

 /**
  * {@inheritdoc}
  */
 protected function writePrompt(OutputInterface $output, Question $question)
 {
     $text = $question->getQuestion();
     $default = $question->getDefault();
     $choices = $question->getChoices();
     $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
     $output->writeln($text);
     $output->write(' > ');
 }
開發者ID:opdavies,項目名稱:drupal-vm-generator,代碼行數:12,代碼來源:DrupalVmChoiceQuestionHelper.php

示例3: ask

 /**
  * Asks a question to the user.
  *
  * @param InputInterface  $input    An InputInterface instance
  * @param OutputInterface $output   An OutputInterface instance
  * @param Question        $question The question to ask
  *
  * @return string The user answer
  *
  * @throws \RuntimeException If there is no data to read in the input stream
  */
 public function ask(InputInterface $input, OutputInterface $output, Question $question)
 {
     if (!$input->isInteractive()) {
         return $question->getDefault();
     }
     if (!$question->getValidator()) {
         return $this->doAsk($output, $question);
     }
     $interviewer = function () use($output, $question) {
         return $this->doAsk($output, $question);
     };
     return $this->validateAttempts($interviewer, $output, $question);
 }
開發者ID:nuwe1,項目名稱:symfony,代碼行數:24,代碼來源:QuestionHelper.php

示例4: ask

 /**
  * Asks a question to the user.
  *
  * @param InputInterface  $input    An InputInterface instance
  * @param OutputInterface $output   An OutputInterface instance
  * @param Question        $question The question to ask
  *
  * @return string The user answer
  *
  * @throws RuntimeException If there is no data to read in the input stream
  */
 public function ask(InputInterface $input, OutputInterface $output, Question $question)
 {
     if ($output instanceof ConsoleOutputInterface) {
         $output = $output->getErrorOutput();
     }
     if (!$input->isInteractive()) {
         return $question->getDefault();
     }
     if (!$question->getValidator()) {
         return $this->doAsk($output, $question);
     }
     $that = $this;
     $interviewer = function () use($output, $question, $that) {
         return $that->doAsk($output, $question);
     };
     return $this->validateAttempts($interviewer, $output, $question);
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:28,代碼來源:QuestionHelper.php


注:本文中的Symfony\Component\Console\Question\Question::getDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。