12 namespace Symfony\Component\Console\Helper;
34 $question->
setValidator(
function ($value) use ($validator) {
35 if (null !== $validator && is_callable($validator)) {
36 $value = $validator($value);
40 if (!is_array($value) && !is_bool($value) && 0 ===
strlen($value)) {
41 throw new \Exception(
'A value is required.');
47 return parent::ask($input, $output, $question);
59 case null === $default:
60 $text = sprintf(
' <info>%s</info>:', $text);
65 $text = sprintf(
' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ?
'yes' :
'no');
70 $choices = $question->getChoices();
71 $text = sprintf(
' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
76 $text = sprintf(
' <info>%s</info> [<comment>%s</comment>]:', $text, $default);
82 $width = max(array_map(
'strlen', array_keys($question->getChoices())));
84 foreach ($question->getChoices() as $key => $value) {
85 $output->
writeln(sprintf(
" [<comment>%-${width}s</comment>] %s", $key, $value));
89 $output->
write(
' > ');
99 $output->error($error->getMessage());
104 parent::writeError($output, $error);