Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 13 |
EnforcedFormResponseSubscriber | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 13 |
onKernelException | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
onKernelResponse | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
getSubscribedEvents | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\Core\EventSubscriber\EnforcedFormResponseSubscriber. | |
*/ | |
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\HttpKernelInterface; | |
use Symfony\Component\HttpKernel\KernelEvents; | |
/** | |
* Handle the EnforcedResponseException and deliver an EnforcedResponse. | |
*/ | |
class EnforcedFormResponseSubscriber implements EventSubscriberInterface { | |
/** | |
* Replaces the response in case an EnforcedResponseException was thrown. | |
*/ | |
public function onKernelException(GetResponseForExceptionEvent $event) { | |
if ($response = EnforcedResponse::createFromException($event->getException())) { | |
// Setting the response stops the event propagation. | |
$event->setResponse($response); | |
} | |
} | |
/** | |
* Unwraps an enforced response. | |
*/ | |
public function onKernelResponse(FilterResponseEvent $event) { | |
$response = $event->getResponse(); | |
if ($response instanceof EnforcedResponse && $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) { | |
$event->setResponse($response->getResponse()); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function getSubscribedEvents() { | |
$events[KernelEvents::EXCEPTION] = array('onKernelException', 128); | |
$events[KernelEvents::RESPONSE] = array('onKernelResponse', 128); | |
return $events; | |
} | |
} |