ConsoleSignalEvent.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Event;
  11. use Symfony\Component\Console\Command\Command;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. /**
  15. * @author marie <marie@users.noreply.github.com>
  16. */
  17. final class ConsoleSignalEvent extends ConsoleEvent
  18. {
  19. private int $handlingSignal;
  20. private int|false $exitCode;
  21. public function __construct(Command $command, InputInterface $input, OutputInterface $output, int $handlingSignal, int|false $exitCode = 0)
  22. {
  23. parent::__construct($command, $input, $output);
  24. $this->handlingSignal = $handlingSignal;
  25. $this->exitCode = $exitCode;
  26. }
  27. public function getHandlingSignal(): int
  28. {
  29. return $this->handlingSignal;
  30. }
  31. public function setExitCode(int $exitCode): void
  32. {
  33. if ($exitCode < 0 || $exitCode > 255) {
  34. throw new \InvalidArgumentException('Exit code must be between 0 and 255.');
  35. }
  36. $this->exitCode = $exitCode;
  37. }
  38. public function abortExit(): void
  39. {
  40. $this->exitCode = false;
  41. }
  42. public function getExitCode(): int|false
  43. {
  44. return $this->exitCode;
  45. }
  46. }