class GetResponseForExceptionEvent

Allows to create a response for a thrown exception

Call setResponse() to set the response that will be returned for the current request. The propagation of this event is stopped as soon as a response is set.

You can also call setException() to replace the thrown exception. This exception will be thrown if no response is set during processing of this event.

@author Bernhard Schussek <bschussek@gmail.com>

@api

Hierarchy

Expanded class hierarchy of GetResponseForExceptionEvent

5 files declare their use of GetResponseForExceptionEvent
ExceptionListener.php in drupal/core/lib/Drupal/Core/EventSubscriber/ExceptionListener.php
ExceptionListener.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php
ExceptionListenerTest.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php
HttpKernel.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php
ProfilerListener.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Event/GetResponseForExceptionEvent.php, line 32

Namespace

Symfony\Component\HttpKernel\Event
View source
class GetResponseForExceptionEvent extends GetResponseEvent {

  /**
   * The exception object
   * @var \Exception
   */
  private $exception;
  public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, \Exception $e) {
    parent::__construct($kernel, $request, $requestType);
    $this
      ->setException($e);
  }

  /**
   * Returns the thrown exception
   *
   * @return \Exception  The thrown exception
   *
   * @api
   */
  public function getException() {
    return $this->exception;
  }

  /**
   * Replaces the thrown exception
   *
   * This exception will be thrown if no response is set in the event.
   *
   * @param \Exception $exception The thrown exception
   *
   * @api
   */
  public function setException(\Exception $exception) {
    $this->exception = $exception;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Event::$dispatcher private property
Event::$name private property
Event::$propagationStopped private property
Event::getDispatcher public function Returns the EventDispatcher that dispatches this Event
Event::getName public function Gets the event's name.
Event::isPropagationStopped public function Returns whether further event listeners should be triggered.
Event::setDispatcher public function Stores the EventDispatcher that dispatches this Event
Event::setName public function Sets the event's name property.
Event::stopPropagation public function Stops the propagation of the event to further event listeners.
GetResponseEvent::$response private property The response object
GetResponseEvent::getResponse public function Returns the response object
GetResponseEvent::hasResponse public function Returns whether a response was set
GetResponseEvent::setResponse public function Sets a response and stops event propagation
GetResponseForExceptionEvent::$exception private property The exception object
GetResponseForExceptionEvent::getException public function Returns the thrown exception
GetResponseForExceptionEvent::setException public function Replaces the thrown exception
GetResponseForExceptionEvent::__construct public function Overrides KernelEvent::__construct
KernelEvent::$kernel private property The kernel in which this event was thrown
KernelEvent::$request private property The request the kernel is currently processing
KernelEvent::$requestType private property The request type the kernel is currently processing. One of HttpKernelInterface::MASTER_REQUEST and HttpKernelInterface::SUB_REQUEST
KernelEvent::getKernel public function Returns the kernel in which this event was thrown
KernelEvent::getRequest public function Returns the request the kernel is currently processing
KernelEvent::getRequestType public function Returns the request type the kernel is currently processing