ConsoleAlarmEvent.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. final class ConsoleAlarmEvent extends ConsoleEvent
  15. {
  16. public function __construct(
  17. Command $command,
  18. InputInterface $input,
  19. OutputInterface $output,
  20. private int|false $exitCode = 0,
  21. ) {
  22. parent::__construct($command, $input, $output);
  23. }
  24. public function setExitCode(int $exitCode): void
  25. {
  26. if ($exitCode < 0 || $exitCode > 255) {
  27. throw new \InvalidArgumentException('Exit code must be between 0 and 255.');
  28. }
  29. $this->exitCode = $exitCode;
  30. }
  31. public function abortExit(): void
  32. {
  33. $this->exitCode = false;
  34. }
  35. public function getExitCode(): int|false
  36. {
  37. return $this->exitCode;
  38. }
  39. }