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(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()) {