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

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