question = new ConfirmationQuestion('Continue (y/n)? [' . ($this->defaultContinueAnswer ? 'y' : 'n') . '] ', $this->defaultContinueAnswer); } protected function configure(): void { $this ->setName($this->name) ->setDescription($this->description); } /** * @psalm-suppress PossiblyUnusedProperty */ protected function execute(InputInterface $input, OutputInterface $output): int { $this->setOutput($output); $this->setInput($input); if ($this->requestConfirmation($input, $output)) { return 1; } return $this->runCommands(); } protected function requestConfirmation(InputInterface $input, OutputInterface $output): int { if ($input->isInteractive()) { /** @var QuestionHelper */ $this->helper = $this->getHelper('question'); foreach ($this->operationHints as $hint) { $this->printComment($hint); } $this->printNewLine(); if (!$this->helper->ask($input, $output, $this->question)) { return 1; } } return 0; } protected function runCommands(): int { throw new LogicException('You must override the runCommands() method in the concrete command class.'); } protected function setOutput(OutputInterface $output): void { $this->output = $output; } protected function setInput(InputInterface $input): void { $this->input = $input; } protected function printNewLine(): void { $this->output->writeln(''); } protected function printInfo(string|array $messages, string $prefix = ''): void { if (is_array($messages)) { foreach ($messages as $message) { $this->output->writeln('' . $prefix . $message . ''); } return; } $this->output->writeln('' . $prefix . $messages . ''); } protected function printComment(string|array $messages, string $prefix = ''): void { if (is_array($messages)) { foreach ($messages as $message) { $this->output->writeln('' . $prefix . $message . ''); } return; } $this->output->writeln('' . $prefix . $messages . ''); } }