vendor/uvdesk/api-bundle/EventListeners/API/KernelRequest.php line 35

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\ApiBundle\EventListeners\API;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
  5. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. class KernelRequest
  8. {
  9.     private $firewall;
  10.     public function __construct(FirewallMap $firewall)
  11.     {
  12.         $this->firewall $firewall;
  13.     }
  14.     public function onKernelRequest(RequestEvent $event)
  15.     {
  16.         if (!$event->isMasterRequest()) {
  17.             return;
  18.         }
  19.         
  20.         $request $event->getRequest();
  21.         $method  $request->getRealMethod();
  22.         if ('OPTIONS' == $method) {
  23.             $event->setResponse(new Response());
  24.         }
  25.         return;
  26.     }
  27.     public function onKernelResponse(ResponseEvent $event)
  28.     {
  29.         $request $event->getRequest();
  30.         
  31.         if (!$event->isMasterRequest()) {
  32.             return;
  33.         }
  34.         if ('OPTIONS' == $request->getRealMethod() || 'POST' == $request->getRealMethod() || 'GET' == $request->getRealMethod()) {
  35.             $response $event->getResponse();
  36.             
  37.             $response->headers->set('Access-Control-Allow-Origin''*');
  38.             $response->headers->set('Access-Control-Allow-Methods''GET,POST,PUT,OPTIONS');
  39.             $response->headers->set('Access-Control-Allow-Headers', ['Access-Control-Allow-Origin''Authorization''Content-Type']);
  40.         }
  41.         
  42.         return;
  43.     }
  44. }