本文整理汇总了PHP中Symfony\Component\Console\Question\ChoiceQuestion::setAutocompleterValues方法的典型用法代码示例。如果您正苦于以下问题:PHP ChoiceQuestion::setAutocompleterValues方法的具体用法?PHP ChoiceQuestion::setAutocompleterValues怎么用?PHP ChoiceQuestion::setAutocompleterValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Question\ChoiceQuestion
的用法示例。
在下文中一共展示了ChoiceQuestion::setAutocompleterValues方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
/** @var StorageInterface $storage */
$storage = $this->getContainer()->get('storage');
$files = $input->getArgument('files');
if ($input->getOption('latest')) {
$remoteFiles = $storage->remoteListing();
if (count($remoteFiles) > 0) {
$files[] = end($remoteFiles);
$input->setArgument('files', $files);
}
}
if ($input->hasArgument('files') && !empty($files)) {
return;
}
$remoteFiles = $storage->remoteListing();
$localFiles = $storage->localListing();
if (count(array_diff($remoteFiles, $localFiles)) === 0) {
$output->writeln('All files fetched');
return;
}
$helper = $this->getHelper('question');
$question = new ChoiceQuestion('Which backup', array_values(array_diff($remoteFiles, $localFiles)));
$question->setMultiselect(true);
$question->setErrorMessage('Backup %s is invalid.');
$question->setAutocompleterValues([]);
$input->setArgument('files', $helper->ask($input, $output, $question));
}
示例2: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
if ($input->getArgument('file')) {
return;
}
/** @var StorageInterface $storage */
$storage = $this->getContainer()->get('storage');
$localFiles = $storage->localListing();
$helper = $this->getHelper('question');
$question = new ChoiceQuestion('Which backup', $localFiles);
$question->setErrorMessage('Backup %s is invalid.');
$question->setAutocompleterValues([]);
$input->setArgument('file', $helper->ask($input, $output, $question));
$output->writeln('');
}
示例3: choose
/**
* @param array $items An associative array of choices.
* @param string $text Some text to precede the choices.
* @param InputInterface $input
* @param OutputInterface $output
* @param mixed $default A default (as a key in $items).
*
* @throws \RuntimeException on failure
*
* @return mixed
* The chosen item (as a key in $items).
*/
public function choose(array $items, $text = 'Enter a number to choose an item:', InputInterface $input, OutputInterface $output, $default = null)
{
if (count($items) === 1) {
return key($items);
}
$itemList = array_values($items);
$defaultKey = $default !== null ? array_search($default, $itemList) : null;
$question = new ChoiceQuestion($text, $itemList, $defaultKey);
$question->setMaxAttempts(5);
// Unfortunately the default autocompletion can cause '2' to be
// completed to '20', etc.
$question->setAutocompleterValues(null);
$choice = $this->ask($input, $output, $question);
$choiceKey = array_search($choice, $items);
if ($choiceKey === false) {
throw new \RuntimeException("Invalid value: {$choice}");
}
return $choiceKey;
}
示例4: askQuestions
/**
* Ask questions
*
* @param Set $set A Certificationy questions Set instance
* @param InputInterface $input A Symfony Console input instance
* @param OutputInterface $output A Symfony Console output instance
*/
protected function askQuestions(Set $set, InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getHelper('question');
$showMultipleChoice = $input->getOption('show-multiple-choice');
$questionCount = 1;
foreach ($set->getQuestions() as $i => $question) {
$choiceQuestion = new ChoiceQuestion(sprintf('Question <comment>#%d</comment> [<info>%s</info>] %s' . ($showMultipleChoice === true ? "\n" . 'This question <comment>' . ($question->isMultipleChoice() === true ? 'IS' : 'IS NOT') . "</comment> multiple choice." : ""), $questionCount++, $question->getCategory(), $question->getQuestion()), $question->getAnswersLabels());
$multiSelect = $showMultipleChoice === true ? $question->isMultipleChoice() : true;
$numericOnly = 1 === array_product(array_map('is_numeric', $question->getAnswersLabels()));
$choiceQuestion->setMultiselect($multiSelect);
$choiceQuestion->setErrorMessage('Answer %s is invalid.');
$choiceQuestion->setAutocompleterValues($numericOnly ? null : $question->getAnswersLabels());
$answer = $questionHelper->ask($input, $output, $choiceQuestion);
$answers = true === $multiSelect ? $answer : array($answer);
$answer = true === $multiSelect ? implode(', ', $answer) : $answer;
$set->setAnswer($i, $answers);
if ($input->getOption("training")) {
$uniqueSet = new Set(array($i => $question));
$uniqueSet->setAnswer($i, $answers);
$this->displayResults($uniqueSet, $output);
}
$output->writeln('<comment>✎ Your answer</comment>: ' . $answer . "\n");
}
}
示例5: chooseIncludeExamples
private function chooseIncludeExamples()
{
$default = 'i';
$choices = ['i' => 'Include examples', 'e' => 'Export to a separate file', 's' => 'Skip examples'];
$question = new ChoiceQuestion("Do you want to include code examples (default: {$default})?", $choices, $default);
$question->setMultiselect(false);
$question->setAutocompleterValues(null);
$question->setValidator(function ($val) {
return $val;
});
return $this->helper->ask($this->input, $this->output, $question);
}
示例6: getTogglApi
private function getTogglApi()
{
$tokens = $this->_config['toggl_token'];
if (is_array($tokens)) {
$question = new ChoiceQuestion('<question>For which team member do you want to invoice time entries?</question>', $tokens);
$question->setAutocompleterValues(array_keys($tokens));
$question->setErrorMessage('Answer is invalid.');
$answer = $this->_questionHelper->ask($this->_input, $this->_output, $question);
$token = $tokens[$answer];
} else {
$token = $tokens;
}
return TogglClient::factory(array('api_key' => $token, 'debug' => self::DEBUG_MODE));
}