Ask a simple question which requires input.

@param string   $questionText
@param mixed    $default
@param array    $autoCompleterValues
@param callable $validator

@return string
The user's answer.
163937
public function askInput($questionText, $default = null, array $autoCompleterValues = [], callable $validator = null)
    {
        if ($default !== null) {
            $questionText .= ' <question>[' . $default . ']</question>';
        }
        $questionText .= ': ';
        $question = new Question($questionText, $default);
        if (!empty($autoCompleterValues)) {
            $question->setAutocompleterValues($autoCompleterValues);
        }
        if ($validator !== null) {
            $question->setValidator($validator);
            $question->setMaxAttempts(5);
        }

        return $this->ask($this->input, $this->output, $question);
    }
1222436
protected function ask($question, $default = null, Closure $validator = null)
    {
        if ($default) {
            $question .= " [$default]";
        }

        $question = new Question($question . "\n > ", $default);

        if ($validator) {
            $question->setValidator($validator);
        }

        return trim($this->getHelper('question')->ask($this->input, $this->output, $question));
    }
175790
protected function askQuestion($question, $choices, $default)
	{
		// Ask until we get a valid response
		do
		{
			echo $question.' '.$choices.': ';
			
			$handle = fopen("php://stdin", "r");
			$line = fgets($handle);

			$response = trim($line);

			// Use default when no response is given
			if (empty($response))
				$response = $default;
		}
		while (!in_array($response, explode('/', $choices)));

		return $response;
	}
994329
public function askThenRemove(InputInterface $input, OverwritableOutputInterface $output, Question $question)
    {
        // Following suit of ask().
        if (!$input->isInteractive()) {
            return $question->getDefault();
        }

        $this->remove = true;
        $this->question = $question;
        $this->output = $output;
        $this->autocomplete = $this->question->getAutocompleterValues() !== null && $this->hasSttyAvailable();

        $this->output->capture();

        // Wrap normalizer to remove latest question & answer since
        // it is called for each iteration if answer is not valid.
        $normalizer = $question->getNormalizer();
        $question->setNormalizer(function ($value) use ($normalizer) {
            $this->output->remove();
            $this->output->capture();

            if (is_callable($normalizer)) {
                return $normalizer($value);
            }

            return $value;
        });

        try {
            $value = $this->ask($input, $this->output, $question);
        } finally {
            $this->remove = false;
            $this->question = null;
            $this->output->remove();
            $this->output = null;
        }

        return $value;
    }
930523
public function ask($question, $default = null)
    {
        $question = new Question("<question>$question</question> ", $default);

        return $this->helper('question')->ask($this->input, $this->output, $question);
    }
833605
public function evaluateQuestion(array $questionRaw, PhpStringParser $parser, GeneratorDataObject $generator)
    {
        $iterator       = $this->iteratorValidator->retrieveValidIteration($questionRaw, $generator, $parser);
        $iteratorParser = clone $parser;

        foreach ($iterator as $iteration) {
            $iteratorParser->addVariable('iteration', $iteration);

            $origine = $iteratorParser->parse($questionRaw['iteration']['retrieveBy']);

            $question = new SimpleQuestion(
                $iteratorParser->parse($questionRaw['iteration']['text']),
                $questionRaw['setter'] . $origine
            );
            $question->setDefaultResponse((isset($questionRaw['iteration']['response']['default']) === true)
                    ? $iteratorParser->parse($questionRaw['iteration']['response']['default']) : null);
            $question->setRequired($questionRaw['required']);
            $question->setHelpMessage($questionRaw['helpMessage']);
            $question->setResponseType(new QuestionResponseTypeEnum($questionRaw['iteration']['response']['type']));

            $response = $this->context->ask($question);

            $questionName = $questionRaw['setter'];
            if ($response !== null) {
                $generator->getDto()->$questionName($origine, $response);
            }
        }

        return $generator;
    }
1295360
public function ask(string $question, $default = null)
	{
		$this->output->write(trim($question) . ' ');

		$answer = $this->input->read();

		return empty($answer) ? $default : $answer;
	}
210922
function (question, defaultValue) {
  // For simplicity we uncheck all boxes and
  // use .default to set the active ones.
  _.each(question.choices, function (choice) {
    if (typeof choice === 'object') {
      choice.checked = false;
    }
  });

  return defaultValue;
}
1280203
public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
    {
        $helper = $this->getHelperSet()->get('question');

        $question = new ChoiceQuestion("<question>$question</question> ", $choices, $default);

        $question->setMaxAttempts($attempts)->setMultiselect($multiple);

        return $helper->ask($this->input, $this->output, $question);
    }
703573
public function validationDefault(Validator $validator) {
		if (!empty($this->validate)) {
			foreach ($this->validate as $field => $rules) {
				if (is_int($field)) {
					$field = $rules;
					$rules = [];
				}
				if (!$rules) {
					continue;

				}
				$rules = (array)$rules;

				foreach ($rules as $key => $rule) {
					if (is_string($rule)) {
						$ruleArray = ['rule' => $rule];
						$rules[$rule] = $ruleArray;
						unset($rules[$key]);
						$key = $rule;
						$rule = $ruleArray;
					}

					if (isset($rule['required'])) {
						$validator->requirePresence($field, $rule['required']);
						unset($rules[$key]['required']);
					}
					if (isset($rule['allowEmpty'])) {
						$validator->allowEmpty($field, $rule['allowEmpty']);
						unset($rules[$key]['allowEmpty']);
					}
					if (isset($rule['message'])) {
						if (is_array($rule['message'])) {
							$name = array_shift($rule['message']);
							//$args = array_slice($rule['message'], 1);
							$args = $this->_translateArgs($rule['message']);
							$message = __d($this->validationDomain, $name, $args);
						} else {
							$message = __d($this->validationDomain, $rule['message']);
						}
						$rules[$key]['message'] = $message;
					}

					if (!empty($rules[$key]['rule']) && ($rules[$key]['rule'] === 'notEmpty' || $rules[$key]['rule'] === ['notEmpty'])) {
						$rules[$key]['rule'] = 'notBlank';
					}

					if (!empty($rules[$key]['rule']) && ($rules[$key]['rule'] === 'isUnique' || $rules[$key]['rule'] === ['isUnique'])) {
						$rules[$key]['rule'] = 'validateUnique';
						$rules[$key]['provider'] = 'table';
					}
				}

				$validator->add($field, $rules);
			}
		}

		return $validator;
	}
64998
final protected function askInput($question, $defaultValue)
    {
        $indent = ($this->indent > 0) ? $this->indent : 0;
        $prompt = empty($defaultValue) && 0 !== $defaultValue ? '' : sprintf(' [<info>%s</info>]', $defaultValue);
        $question = sprintf('%s%s%s: ', str_repeat(' ', 4 * $indent), $question, $prompt);

        $question = new Question($question, $defaultValue);
        return $this->getHelper('question')->ask($this->input, $this->output, $question);
    }
989691
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('name', 'create')
            ->notEmpty('name');

        $validator
            ->allowEmpty('description');

        $validator
            ->integer('status')
            ->requirePresence('status', 'create')
            ->notEmpty('status');

        $validator
            ->integer('priority')
            ->requirePresence('priority', 'create')
            ->notEmpty('priority');

        $validator
            ->date('deadline')
            ->allowEmpty('deadline');

        $validator
            ->decimal('cost')
            ->allowEmpty('cost');

        return $validator;
    }
536212
protected function select($text, $choices, $default = null)
    {
        $question = new ChoiceQuestion($text, $choices, $default);

        return $this->getHelper('question')->ask($this->input, $this->output, $question);
    }
1010709
protected function getConfirmationQuestion(string $questionName, bool $defaultValue = false): ConfirmationQuestion
    {
        return new ConfirmationQuestion(
            sprintf(
                '<info>%s</info> [<comment>%s</comment>]? ',
                $questionName,
                $defaultValue ? 'yes' : 'no'
            ),
            $defaultValue
        );
    }
119085
public function shortanswerStatement($translatorevent, $questionAttempt, $question) {

        $translatorevent['interaction_type'] = 'fill-in';
        $translatorevent['interaction_correct_responses'] = [];

        foreach ($question->answers as $answer) {
            if (intval($answer->fraction) === 1) {
                $correctResponse;
                if ($question->shortanswer->options->usecase == '1') {
                    $correctResponse = '{case_matters=true}'.$answer->answer;
                } else {
                    $correctResponse = '{case_matters=false}'.$answer->answer;
                }
                array_push($translatorevent['interaction_correct_responses'], $correctResponse);
            }
        }

        return $translatorevent;
    }
9610
public function ask($question, $default = null)
	{
		$dialog = $this->getHelperSet()->get('dialog');

		return $dialog->ask($this->output, "<question>$question</question>", $default);
	}
357153
final protected function askAndValidate(
        InputInterface $input,
        OutputInterface $output,
        $questionText,
        $default,
        $validator
    ) {
        $questionHelper = $this->getQuestionHelper();

        $question = new Question($questionHelper->getQuestion($questionText, $default), $default);

        $question->setValidator($validator);

        return $questionHelper->ask($input, $output, $question);
    }