application_signalable.php 1002 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use Symfony\Component\Console\Application;
  3. use Symfony\Component\Console\Command\SignalableCommandInterface;
  4. use Symfony\Component\Console\Helper\QuestionHelper;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use Symfony\Component\Console\Question\ChoiceQuestion;
  8. use Symfony\Component\Console\SingleCommandApplication;
  9. $vendor = __DIR__;
  10. while (!file_exists($vendor.'/vendor')) {
  11. $vendor = \dirname($vendor);
  12. }
  13. require $vendor.'/vendor/autoload.php';
  14. (new class() extends SingleCommandApplication implements SignalableCommandInterface {
  15. public function getSubscribedSignals(): array
  16. {
  17. return [SIGINT];
  18. }
  19. public function handleSignal(int $signal): void
  20. {
  21. exit;
  22. }
  23. })
  24. ->setCode(function(InputInterface $input, OutputInterface $output) {
  25. $this->getHelper('question')
  26. ->ask($input, $output, new ChoiceQuestion('😊', ['y']));
  27. return 0;
  28. })
  29. ->run()
  30. ;