EnforcedResponse::createFromException

public static function EnforcedResponse::createFromException

public static EnforcedResponse::createFromException(\Exception $e)

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

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

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();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!EnforcedResponse.php/function/EnforcedResponse::createFromException/8.1.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部