<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class ResponseSubscriber implements EventSubscriberInterface
{
public function onKernelResponse(ResponseEvent $event)
{
if ('OPTIONS' === $event->getRequest()->getMethod()) {
$response = $event->getResponse();
$response->headers->set('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
$response->setStatusCode(200);
}
}
public static function getSubscribedEvents()
{
return [
'kernel.response' => 'onKernelResponse',
];
}
}