ConsoleExceptionEvent.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 handle exception thrown in a command.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class ConsoleExceptionEvent extends ConsoleEvent
  20. {
  21. private $exception;
  22. private $exitCode;
  23. public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode)
  24. {
  25. parent::__construct($command, $input, $output);
  26. $this->setException($exception);
  27. $this->exitCode = (int) $exitCode;
  28. }
  29. /**
  30. * Returns the thrown exception.
  31. *
  32. * @return \Exception The thrown exception
  33. */
  34. public function getException()
  35. {
  36. return $this->exception;
  37. }
  38. /**
  39. * Replaces the thrown exception.
  40. *
  41. * This exception will be thrown if no response is set in the event.
  42. *
  43. * @param \Exception $exception The thrown exception
  44. */
  45. public function setException(\Exception $exception)
  46. {
  47. $this->exception = $exception;
  48. }
  49. /**
  50. * Gets the exit code.
  51. *
  52. * @return int The command exit code
  53. */
  54. public function getExitCode()
  55. {
  56. return $this->exitCode;
  57. }
  58. }