custom/plugins/GrimmDocumentSignature/src/Subscriber/HeaderOptionsSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace GrimmDocumentSignature\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\KernelEvents;
  5. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  6. class HeaderOptionsSubscriber implements EventSubscriberInterface
  7. {
  8.   public static function getSubscribedEvents(): array
  9.   {
  10.     return [
  11.       KernelEvents::RESPONSE => 'setCustomXFrameOptions',
  12.     ];
  13.   }
  14.   /**
  15.    * Set the header option to same origin to display the pdf in an iFrame
  16.    *
  17.    * @param ResponseEvent $event
  18.    *
  19.    * @return void
  20.    */
  21.   public function setCustomXFrameOptions(ResponseEvent $event)
  22.   {
  23.     if (str_starts_with($event->getRequest()->getPathInfo(), '/document/displayDocument/')) {
  24.       $response $event->getResponse();
  25.       $response->headers->set('X-Frame-Options''same-origin');
  26.     }
  27.   }
  28. }