vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/EventListener/XFrameOptionsSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\CoreBundle\EventListener;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. final class XFrameOptionsSubscriber implements EventSubscriberInterface
  16. {
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             KernelEvents::RESPONSE => 'onKernelResponse',
  21.         ];
  22.     }
  23.     public function onKernelResponse(ResponseEvent $event): void
  24.     {
  25.         if (!$this->isMainRequest($event)) {
  26.             return;
  27.         }
  28.         $response $event->getResponse();
  29.         $response->headers->set('X-Frame-Options''sameorigin');
  30.     }
  31.     private function isMainRequest(ResponseEvent $event): bool
  32.     {
  33.         if (\method_exists($event'isMainRequest')) {
  34.             return $event->isMainRequest();
  35.         }
  36.         return $event->isMasterRequest();
  37.     }
  38. }