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

@return mixed
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);
    }
1099196
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('subject', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('comment', 'You need to provide a comment subject.'),
                ],
                'length' => [
                    'rule' => ['minLength', 5],
                    'message' => 'Comment subject need to be at least 5 characters long',
                ]
            ])
            ->add('body', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('comment', 'Your comment message cannot be empty')
                ],
                'length' => [
                    'rule' => ['minLength', 5],
                    'message' => 'Comment message need to be at least 5 characters long',
                ]
            ])
            ->allowEmpty('user_id')
            ->allowEmpty('parent_id')
            ->add('parent_id', 'checkParentId', [
                'rule' => function ($value, $context) {
                    if (!empty($value)) {
                        // make sure it's a valid parent: exists and belongs to the
                        // the same bundle (table)
                        $conditions = [
                            'id' => $value,
                            'entity_id' => $context['data']['entity_id'],
                            'table_alias' => $context['data']['table_alias'],
                        ];

                        return TableRegistry::get('Comment.Comments')->find()
                            ->where($conditions)
                            ->count() > 0;
                    } else {
                        $context['data']['parent_id'] = null;
                    }

                    return true;
                },
                'message' => __d('comment', 'Invalid parent comment!.'),
                'provider' => 'table',
            ]);

        return $validator;
    }
135938
public function choose($question, array $choices, $default = null)
    {
        $helper = $this->getHelper('question');

        $question = new ChoiceQuestion($question, $choices, $default);

        $question->setErrorMessage('Option %s is invalid.');

        return $helper->ask($this->input, $this->getOutputInterface(), $question);
    }
1089826
public function getValidationMessages($validator = null)
    {
        if ($validator) {
            return isset($this->validationMessages[$validator]) ? $this->validationMessages[$validator] : null;
        }

        return $this->validationMessages;
    }
337711
public function validationDefault(Validator $validator)
    {
        $validator
            ->notEmpty('handler', __d('field', 'Invalid field type.'))
            ->add('label', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('field', 'You need to provide a label.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('field', 'Label need to be at least 3 characters long'),
                ],
            ]);

        return $validator;
    }
144152
public function validationDefault(Validator $validator)
    {
        $validator
            ->requirePresence('name')
            ->add('name', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('content', 'You need to provide a content type name.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('content', 'Name need to be at least 3 characters long.'),
                ],
            ])
            ->requirePresence('slug', 'create')
            ->notEmpty('slug', __d('content', 'Machine-name cannot be left empty.'), 'create')
            ->add('slug', 'checkSlug', [
                'rule' => function ($value, $context) {
                    return (preg_match('/^[a-z0-9\-]{3,}$/', $value) === 1);
                },
                'message' => __d('content', 'Invalid machine-name.'),
            ])
            ->requirePresence('title_label')
            ->add('title_label', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('content', 'You need to provide a "Title Label".'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('content', '"Title Label" need to be at least 3 characters long.'),
                ],
            ]);

        return $validator;
    }
446003
protected function askQuestion(string $description, string $default)
    {
        $helper   = $this->getHelper('question');
        $question = new Question($description, $default);
        $answer   = $helper->ask($this->input, $this->output, $question);

        return $answer;
    }
385248
public static function validText(
        $msg = '',
        $options = [],
        $default = null,
        $noValidMessage = null,
        $attemptTimes = 3,
        $failCloseMessage = false
    ) {
        $prompter = new ValidatePrompter();

        $prompter->setOptions($options);

        static::prepareCallbackPrompter($prompter, $noValidMessage, $attemptTimes, $failCloseMessage);

        return $prompter->ask($msg, $default);
    }
1186211
public function choose($question, $choice = 'yn', $default = 'n')
    {
        if (!is_string($choice)) {
            $choice = implode('', $choice);
        }

        $lowercase = str_ireplace($default, strtoupper($default), strtolower($choice));
        $choices = trim(implode('/', preg_split('//', $lowercase)), '/');
        $line = $this->prompt(sprintf('%s [%s]', $question, $choices), $default, '');

        if (stripos($choice, $line) !== false) {
            return strtolower($line);
        }

        return strtolower($default);
    }
1168993
private function askAndValidate(InputInterface $input, OutputInterface $output, $questionText, $default, $validator)
    {
        $questionHelper = $this->getQuestionHelper();

        // NEXT_MAJOR: Remove this BC code for SensioGeneratorBundle 2.3/2.4 after dropping support for Symfony 2.3
        if ($questionHelper instanceof DialogHelper) {
            return $questionHelper->askAndValidate($output, $questionHelper->getQuestion($questionText, $default), $validator, false, $default);
        }

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

        $question->setValidator($validator);

        return $questionHelper->ask($input, $output, $question);
    }
64469
protected function ask($question, $default = null)
    {
        $defaultComment = '';
        
        if ($default !== null) {
            $defaultComment = ' [<comment>' . $default . '</comment>]';
        }
        
        $question = preg_replace('/(?:(\?)\s*$|(\?)?\s+$)|(?<!\s|\?)$/', $defaultComment . '$1 ', $question);
        
        return $this->io->ask($question, $default);
    }
517822
public function getQuestionConfirm(
        $question,
        $default = 'y',
        array $options = array('y', 'n'),
        $required = true
    ) {
        return $this->getQuestion($question, $default, $options, $required);
    }
117004
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

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

        $validator
            ->allowEmpty('url');

        $validator
            ->boolean('new_window')
            ->allowEmpty('new_window');

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

        $validator
            ->allowEmpty('icon');

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

        return $validator;
    }
490209
public function validationDefault(Validator $validator)
    {
        return $validator
            ->add('theme', 'validTheme', [
                'rule' => function ($value, $context) {
                    $exists = plugin()
                        ->filter(function ($plugin) use ($value) {
                            return $plugin->isTheme && $plugin->name === $value;
                        })
                        ->first();

                    return !empty($exists);
                },
                'message' => __d('block', 'Invalid theme for region.'),
            ]);
    }
680613
protected function askUser($question, $defaultValue = '')
    {
        if ($this->option('interactive')) {
            return $this->ask($question, $defaultValue);
        }

        return $defaultValue;
    }
732766
public function confirm($question, $default = false)
    {
        $que = new ConfirmationQuestion($question, $default);
        $helper = new SymfonyQuestionHelper();
        return $helper->ask($this->input, $this->output, $que);
    }
338535
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->dateTime('trashed')
            ->allowEmpty('trashed');

        $validator
            ->scalar('response_status')
            ->maxLength('response_status', 255)
            ->allowEmpty('response_status');

        return $validator;
    }