Без опису

GetResponseForExceptionEvent.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\HttpKernel\Event;
  11. use Symfony\Component\Debug\Exception\FatalThrowableError;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpKernel\HttpKernelInterface;
  14. /**
  15. * @deprecated since Symfony 4.3, use ExceptionEvent instead
  16. */
  17. class GetResponseForExceptionEvent extends RequestEvent
  18. {
  19. private $throwable;
  20. private $exception;
  21. private $allowCustomResponseCode = false;
  22. public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, \Throwable $e)
  23. {
  24. parent::__construct($kernel, $request, $requestType);
  25. $this->setThrowable($e);
  26. }
  27. public function getThrowable(): \Throwable
  28. {
  29. return $this->throwable;
  30. }
  31. /**
  32. * Replaces the thrown exception.
  33. *
  34. * This exception will be thrown if no response is set in the event.
  35. */
  36. public function setThrowable(\Throwable $exception): void
  37. {
  38. $this->exception = null;
  39. $this->throwable = $exception;
  40. }
  41. /**
  42. * @deprecated since Symfony 4.4, use getThrowable instead
  43. *
  44. * @return \Exception The thrown exception
  45. */
  46. public function getException()
  47. {
  48. @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use "getThrowable()" instead.', __METHOD__), \E_USER_DEPRECATED);
  49. return $this->exception ?? $this->exception = $this->throwable instanceof \Exception ? $this->throwable : new FatalThrowableError($this->throwable);
  50. }
  51. /**
  52. * @deprecated since Symfony 4.4, use setThrowable instead
  53. *
  54. * @param \Exception $exception The thrown exception
  55. */
  56. public function setException(\Exception $exception)
  57. {
  58. @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use "setThrowable()" instead.', __METHOD__), \E_USER_DEPRECATED);
  59. $this->throwable = $this->exception = $exception;
  60. }
  61. /**
  62. * Mark the event as allowing a custom response code.
  63. */
  64. public function allowCustomResponseCode()
  65. {
  66. $this->allowCustomResponseCode = true;
  67. }
  68. /**
  69. * Returns true if the event allows a custom response code.
  70. *
  71. * @return bool
  72. */
  73. public function isAllowingCustomResponseCode()
  74. {
  75. return $this->allowCustomResponseCode;
  76. }
  77. }