src/EventSubscriber/ResponseSubscriber.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  5. class ResponseSubscriber implements EventSubscriberInterface
  6. {
  7.     public function onKernelResponse(ResponseEvent $event)
  8.     {
  9.         if ('OPTIONS' === $event->getRequest()->getMethod()) {
  10.             $response $event->getResponse();
  11.             $response->headers->set('Access-Control-Allow-Methods''GET,POST,PUT,DELETE');
  12.             $response->setStatusCode(200);
  13.         }
  14.     }
  15.     public static function getSubscribedEvents()
  16.     {
  17.         return [
  18.             'kernel.response' => 'onKernelResponse',
  19.         ];
  20.     }
  21. }