public function askHidden(Input $input, $question, $validator = null) { $question = new Question($question); $question->setHidden(true); $question->setValidator($validator); return $this->askQuestion($input, $question); }
/** * 构造方法 * @param string $question 问题 * @param array $choices 选项 * @param mixed $default 默认答案 */ public function __construct($question, array $choices, $default = null) { parent::__construct($question, $default); $this->choices = $choices; $this->setValidator($this->getDefaultValidator()); $this->setAutocompleterValues($choices); }
/** * 显示问题的提示信息 */ protected function writePrompt() { $text = $this->question->getQuestion(); $default = $this->question->getDefault(); switch (true) { case null === $default: $text = sprintf(' <info>%s</info>:', $text); break; case $this->question instanceof Confirmation: $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no'); break; case $this->question instanceof Choice && $this->question->isMultiselect(): $choices = $this->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 $this->question instanceof Choice: $choices = $this->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); } $this->output->writeln($text); if ($this->question instanceof Choice) { $width = max(array_map('strlen', array_keys($this->question->getChoices()))); foreach ($this->question->getChoices() as $key => $value) { $this->output->writeln(sprintf(" [<comment>%-{$width}s</comment>] %s", $key, $value)); } } $this->output->write(' > '); }
/** * 构造方法 * @param string $question 问题 * @param bool $default 默认答案 * @param string $trueAnswerRegex 验证正则 */ public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i') { parent::__construct($question, (bool) $default); $this->trueAnswerRegex = $trueAnswerRegex; $this->setNormalizer($this->getDefaultNormalizer()); }