ConsoleSignalEvent.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  20. * @var int
  21. */
  22. private $handlingSignal;
  23. /**
  24. * @var int|false
  25. */
  26. private $exitCode;
  27. /**
  28. * @param int|false $exitCode
  29. * @param \Symfony\Component\Console\Command\Command $command
  30. * @param \Symfony\Component\Console\Input\InputInterface $input
  31. * @param \Symfony\Component\Console\Output\OutputInterface $output
  32. * @param int $handlingSignal
  33. */
  34. public function __construct($command, $input, $output, $handlingSignal, $exitCode = 0)
  35. {
  36. parent::__construct($command, $input, $output);
  37. $this->handlingSignal = $handlingSignal;
  38. $this->exitCode = $exitCode;
  39. }
  40. public function getHandlingSignal()
  41. {
  42. return $this->handlingSignal;
  43. }
  44. /**
  45. * @param int $exitCode
  46. */
  47. public function setExitCode($exitCode)
  48. {
  49. if ($exitCode < 0 || $exitCode > 255) {
  50. throw new \InvalidArgumentException('Exit code must be between 0 and 255.');
  51. }
  52. $this->exitCode = $exitCode;
  53. }
  54. public function abortExit()
  55. {
  56. $this->exitCode = false;
  57. }
  58. /**
  59. * @return int|false
  60. */
  61. public function getExitCode()
  62. {
  63. return $this->exitCode;
  64. }
  65. }