EnforcedFormResponseSubscriber.php in Drupal 8
File
core/lib/Drupal/Core/EventSubscriber/EnforcedFormResponseSubscriber.php
View source
<?php
namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Form\EnforcedResponse;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class EnforcedFormResponseSubscriber implements EventSubscriberInterface {
public function onKernelException(GetResponseForExceptionEvent $event) {
if ($response = EnforcedResponse::createFromException($event
->getException())) {
$event
->setResponse($response);
}
}
public function onKernelResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
if ($response instanceof EnforcedResponse && $event
->isMasterRequest()) {
$event
->setResponse($response
->getResponse());
}
}
public static function getSubscribedEvents() {
$events[KernelEvents::EXCEPTION] = [
'onKernelException',
128,
];
$events[KernelEvents::RESPONSE] = [
'onKernelResponse',
128,
];
return $events;
}
}