class SymfonyQuestionHelper in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/console/Helper/SymfonyQuestionHelper.php \Symfony\Component\Console\Helper\SymfonyQuestionHelper
Symfony Style Guide compliant question helper.
@author Kevin Bond <kevinbond@gmail.com>
Hierarchy
- class \Symfony\Component\Console\Helper\Helper implements HelperInterface
- class \Symfony\Component\Console\Helper\QuestionHelper
- class \Symfony\Component\Console\Helper\SymfonyQuestionHelper
- class \Symfony\Component\Console\Helper\QuestionHelper
Expanded class hierarchy of SymfonyQuestionHelper
1 file declares its use of SymfonyQuestionHelper
- SymfonyStyle.php in vendor/
symfony/ console/ Style/ SymfonyStyle.php
File
- vendor/
symfony/ console/ Helper/ SymfonyQuestionHelper.php, line 26
Namespace
Symfony\Component\Console\HelperView source
class SymfonyQuestionHelper extends QuestionHelper {
/**
* {@inheritdoc}
*/
public function ask(InputInterface $input, OutputInterface $output, Question $question) {
$validator = $question
->getValidator();
$question
->setValidator(function ($value) use ($validator) {
if (null !== $validator && is_callable($validator)) {
$value = $validator($value);
}
// make required
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
throw new \Exception('A value is required.');
}
return $value;
});
return parent::ask($input, $output, $question);
}
/**
* {@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:
$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(' > ');
}
/**
* {@inheritdoc}
*/
protected function writeError(OutputInterface $output, \Exception $error) {
if ($output instanceof SymfonyStyle) {
$output
->newLine();
$output
->error($error
->getMessage());
return;
}
parent::writeError($output, $error);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Helper:: |
protected | property | ||
Helper:: |
public static | function | ||
Helper:: |
public static | function | ||
Helper:: |
public | function |
Gets the helper set associated with this helper. Overrides HelperInterface:: |
|
Helper:: |
public | function |
Sets the helper set associated with this helper. Overrides HelperInterface:: |
|
Helper:: |
public static | function | Returns the length of a string, using mb_strwidth if it is available. | |
Helper:: |
public static | function | ||
QuestionHelper:: |
private | property | ||
QuestionHelper:: |
private static | property | ||
QuestionHelper:: |
private static | property | ||
QuestionHelper:: |
private | function | Autocompletes a question. | |
QuestionHelper:: |
public | function | Asks the question to the user. | |
QuestionHelper:: |
private | function | Gets a hidden response from user. | |
QuestionHelper:: |
public | function | Returns the helper's input stream. | |
QuestionHelper:: |
public | function |
Returns the canonical name of this helper. Overrides HelperInterface:: |
|
QuestionHelper:: |
private | function | Returns a valid unix shell. | |
QuestionHelper:: |
private | function | Returns whether Stty is available or not. | |
QuestionHelper:: |
public | function | Sets the input stream to read from when interacting with the user. | |
QuestionHelper:: |
private | function | Validates an attempt. | |
SymfonyQuestionHelper:: |
public | function |
Asks a question to the user. Overrides QuestionHelper:: |
|
SymfonyQuestionHelper:: |
protected | function |
Outputs an error message. Overrides QuestionHelper:: |
|
SymfonyQuestionHelper:: |
protected | function |
Outputs the question prompt. Overrides QuestionHelper:: |