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

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. $request = $event->getRequest();
  23. $method = $request->getRealMethod();
  24. if ('OPTIONS' == $method) {
  25. $event->setResponse(new Response());
  26. }
  27. return;
  28. }
  29. public function onKernelResponse(ResponseEvent $event)
  30. {
  31. $request = $event->getRequest();
  32. if (!$event->isMasterRequest()) {
  33. return;
  34. }
  35. if ('OPTIONS' == $request->getRealMethod() || 'POST' == $request->getRealMethod() || 'GET' == $request->getRealMethod()) {
  36. $response = $event->getResponse();
  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. return;
  42. }
  43. }