当前位置: 首页>>代码示例>>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;未经允许,请勿转载。