<?php
declare(strict_types=1);
namespace App\Framework\Security\ContentSecurityPolicy\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\WebpackEncoreBundle\Event\RenderAssetTagEvent;
class ScriptNonceSubscriber implements EventSubscriberInterface
{
public function __construct(protected readonly ContentSecurityPolicyListener $listener)
{
}
public static function getSubscribedEvents(): array
{
return [
RenderAssetTagEvent::class => 'addNonceToTags',
];
}
public function addNonceToTags(RenderAssetTagEvent $event): void
{
$event->setAttribute('nonce', $this->listener->getNonce());
}
}