ConsoleExceptionEvent.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 Symfony 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. }