ConsoleExceptionEvent.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. @trigger_error(sprintf('The "%s" class is deprecated since version 3.3 and will be removed in 4.0. Use the ConsoleErrorEvent instead.', ConsoleExceptionEvent::class), E_USER_DEPRECATED);
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. /**
  16. * Allows to handle exception thrown in a command.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. *
  20. * @deprecated since version 3.3, to be removed in 4.0. Use ConsoleErrorEvent instead.
  21. */
  22. class ConsoleExceptionEvent extends ConsoleEvent
  23. {
  24. private $exception;
  25. private $exitCode;
  26. public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode)
  27. {
  28. parent::__construct($command, $input, $output);
  29. $this->setException($exception);
  30. $this->exitCode = (int) $exitCode;
  31. }
  32. /**
  33. * Returns the thrown exception.
  34. *
  35. * @return \Exception The thrown exception
  36. */
  37. public function getException()
  38. {
  39. return $this->exception;
  40. }
  41. /**
  42. * Replaces the thrown exception.
  43. *
  44. * This exception will be thrown if no response is set in the event.
  45. *
  46. * @param \Exception $exception The thrown exception
  47. */
  48. public function setException(\Exception $exception)
  49. {
  50. $this->exception = $exception;
  51. }
  52. /**
  53. * Gets the exit code.
  54. *
  55. * @return int The command exit code
  56. */
  57. public function getExitCode()
  58. {
  59. return $this->exitCode;
  60. }
  61. }