class EnforcedFormResponseSubscriber in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/EventSubscriber/EnforcedFormResponseSubscriber.php \Drupal\Core\EventSubscriber\EnforcedFormResponseSubscriber
Handle the EnforcedResponseException and deliver an EnforcedResponse.
Hierarchy
- class \Drupal\Core\EventSubscriber\EnforcedFormResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of EnforcedFormResponseSubscriber
1 string reference to 'EnforcedFormResponseSubscriber'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses EnforcedFormResponseSubscriber
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ EnforcedFormResponseSubscriber.php, line 14
Namespace
Drupal\Core\EventSubscriberView source
class EnforcedFormResponseSubscriber implements EventSubscriberInterface {
/**
* Replaces the response in case an EnforcedResponseException was thrown.
*/
public function onKernelException(ExceptionEvent $event) {
if ($response = EnforcedResponse::createFromException($event
->getThrowable())) {
// Setting the response stops the event propagation.
$event
->setResponse($response);
}
}
/**
* Unwraps an enforced response.
*/
public function onKernelResponse(ResponseEvent $event) {
$response = $event
->getResponse();
if ($response instanceof EnforcedResponse && $event
->isMainRequest()) {
$event
->setResponse($response
->getResponse());
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::EXCEPTION] = [
'onKernelException',
128,
];
$events[KernelEvents::RESPONSE] = [
'onKernelResponse',
128,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EnforcedFormResponseSubscriber:: |
public static | function | ||
EnforcedFormResponseSubscriber:: |
public | function | Replaces the response in case an EnforcedResponseException was thrown. | |
EnforcedFormResponseSubscriber:: |
public | function | Unwraps an enforced response. |