<?php
namespace GrimmDocumentSignature\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class HeaderOptionsSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => 'setCustomXFrameOptions',
];
}
/**
* Set the header option to same origin to display the pdf in an iFrame
*
* @param ResponseEvent $event
*
* @return void
*/
public function setCustomXFrameOptions(ResponseEvent $event)
{
if (str_starts_with($event->getRequest()->getPathInfo(), '/document/displayDocument/')) {
$response = $event->getResponse();
$response->headers->set('X-Frame-Options', 'same-origin');
}
}
}