EnforcedResponseException.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Drupal\Core\Form;
  3. use Symfony\Component\HttpFoundation\Response;
  4. /**
  5. * Custom exception to break out of the main request and enforce a response.
  6. */
  7. class EnforcedResponseException extends \Exception {
  8. /**
  9. * The response to be enforced.
  10. *
  11. * @var \Symfony\Component\HttpFoundation\Response
  12. */
  13. protected $response;
  14. /**
  15. * Constructs a new enforced response exception.
  16. *
  17. * @param \Symfony\Component\HttpFoundation\Response $response
  18. * The response to be enforced.
  19. * @param string $message
  20. * (optional) The exception message.
  21. * @param int $code
  22. * (optional) A user defined exception code.
  23. * @param \Exception $previous
  24. * (optional) The previous exception for nested exceptions
  25. */
  26. public function __construct(Response $response, $message = "", $code = 0, \Exception $previous = NULL) {
  27. parent::__construct($message, $code, $previous);
  28. $this->response = $response;
  29. }
  30. /**
  31. * Return the response to be enforced.
  32. *
  33. * @returns \Symfony\Component\HttpFoundation\Response $response
  34. * The response to be enforced.
  35. */
  36. public function getResponse() {
  37. return $this->response;
  38. }
  39. }