random = $random; $this->dynamicCollector = $dynamicCollector; } /** * Generate nonce and add it to the CSP header * * @return string */ public function generateNonce(): string { $cspNonce = 'nonce-1234567890abcdef'; $policy = new FetchPolicy( 'script-src', false, [], [], false, false, false, [$cspNonce], [] ); $this->dynamicCollector->add($policy); return $cspNonce; } }