ConsoleSignalEvent.php 1.3 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. public function __construct(
  20. Command $command,
  21. InputInterface $input,
  22. OutputInterface $output,
  23. private int $handlingSignal,
  24. private int|false $exitCode = 0,
  25. ) {
  26. parent::__construct($command, $input, $output);
  27. }
  28. public function getHandlingSignal(): int
  29. {
  30. return $this->handlingSignal;
  31. }
  32. public function setExitCode(int $exitCode): void
  33. {
  34. if ($exitCode < 0 || $exitCode > 255) {
  35. throw new \InvalidArgumentException('Exit code must be between 0 and 255.');
  36. }
  37. $this->exitCode = $exitCode;
  38. }
  39. public function abortExit(): void
  40. {
  41. $this->exitCode = false;
  42. }
  43. public function getExitCode(): int|false
  44. {
  45. return $this->exitCode;
  46. }
  47. }