You are here

public static function EnforcedResponse::createFromException in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Form/EnforcedResponse.php \Drupal\Core\Form\EnforcedResponse::createFromException()
  2. 10 core/lib/Drupal/Core/Form/EnforcedResponse.php \Drupal\Core\Form\EnforcedResponse::createFromException()

Constructs a new enforced response from the given exception.

Note that it is necessary to traverse the exception chain when searching for an enforced response. Otherwise it would be impossible to find an exception thrown from within a twig template.

Parameters

\Exception $e: The exception where the enforced response is to be extracted from.

Return value

static|null The enforced response or NULL if the exception chain does not contain a \Drupal\Core\Form\EnforcedResponseException exception.

1 call to EnforcedResponse::createFromException()
EnforcedFormResponseSubscriber::onKernelException in core/lib/Drupal/Core/EventSubscriber/EnforcedFormResponseSubscriber.php
Replaces the response in case an EnforcedResponseException was thrown.

File

core/lib/Drupal/Core/Form/EnforcedResponse.php, line 44

Class

EnforcedResponse
A wrapper containing a response which is to be enforced upon delivery.

Namespace

Drupal\Core\Form

Code

public static function createFromException(\Exception $e) {
  while ($e) {
    if ($e instanceof EnforcedResponseException) {
      return new static($e
        ->getResponse());
    }
    $e = $e
      ->getPrevious();
  }
}