暫無描述

ConsoleTerminateEvent.php 1.2KB

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. * Allows to manipulate the exit code of a command after its execution.
  16. *
  17. * @author Francesco Levorato <git@flevour.net>
  18. *
  19. * @final since Symfony 4.4
  20. */
  21. class ConsoleTerminateEvent extends ConsoleEvent
  22. {
  23. private $exitCode;
  24. public function __construct(Command $command, InputInterface $input, OutputInterface $output, int $exitCode)
  25. {
  26. parent::__construct($command, $input, $output);
  27. $this->setExitCode($exitCode);
  28. }
  29. /**
  30. * Sets the exit code.
  31. *
  32. * @param int $exitCode The command exit code
  33. */
  34. public function setExitCode($exitCode)
  35. {
  36. $this->exitCode = (int) $exitCode;
  37. }
  38. /**
  39. * Gets the exit code.
  40. *
  41. * @return int The command exit code
  42. */
  43. public function getExitCode()
  44. {
  45. return $this->exitCode;
  46. }
  47. }