* @author Alexander M. Turek */ final class PsrResponseListener implements EventSubscriberInterface { private $httpFoundationFactory; public function __construct(HttpFoundationFactoryInterface $httpFoundationFactory = null) { $this->httpFoundationFactory = $httpFoundationFactory ?? new HttpFoundationFactory(); } /** * Do the conversion if applicable and update the response of the event. */ public function onKernelView(ViewEvent $event): void { $controllerResult = $event->getControllerResult(); if (!$controllerResult instanceof ResponseInterface) { return; } $event->setResponse($this->httpFoundationFactory->createResponse($controllerResult)); } /** * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ KernelEvents::VIEW => 'onKernelView', ]; } }