11 use Symfony\Component\Console\Helper\QuestionHelper;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Question\Question;
15 use Symfony\Component\Console\Question\QuestionFactory;
27 private $questionHelper;
34 private $questionFactory;
41 QuestionHelper $questionHelper,
42 QuestionFactory $questionFactory
44 $this->questionHelper = $questionHelper;
45 $this->questionFactory = $questionFactory;
56 public function execute(array $messages, InputInterface $input, OutputInterface
$output)
58 if (!$input->isInteractive()) {
62 $question = $this->getConfirmationQuestion($messages);
63 $answer = $this->questionHelper->ask($input,
$output, $question);
65 return in_array(strtolower($answer), [
'yes',
'y']);
75 private function getConfirmationQuestion(array $messages)
78 $question = $this->questionFactory->create([
79 'question' => implode(PHP_EOL, $messages) . PHP_EOL
82 $question->setValidator(
function ($answer) {
83 if (!in_array(strtolower($answer), [
'yes',
'y',
'no',
'n'])) {
85 new Phrase(
'A [y]es or [n]o selection needs to be made. Select and try again.')