class EnforcedResponse extends Response (View source)

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

The FormBuilder throws an EnforcedResponseException whenever a form desires to explicitly set a response object. Exception handlers capable of setting the response should extract the response object of such an exception using EnforcedResponse::createFromException(). Then wrap it into an EnforcedResponse object and replace the original response with the wrapped response.

Properties

protected Response $response

The wrapped response object.

Methods

static EnforcedResponse|null
createFromException(Throwable $e)

Constructs a new enforced response from the given exception.

__construct(Response $response)

Constructs an enforced response.

Response
getResponse()

Returns the wrapped response.

Details

static EnforcedResponse|null createFromException(Throwable $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

Throwable $e

The exception where the enforced response is to be extracted from.

Return Value

EnforcedResponse|null

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

__construct(Response $response)

Constructs an enforced response.

Use EnforcedResponse::createFromException() instead.

Parameters

Response $response

The response to wrap.

Response getResponse()

Returns the wrapped response.

Return Value

Response

The wrapped response.