Debian Codegraph @

vendor/ipl/web/src/Compat/StyleWithNonce.php

raw
1 <?php
2
3 namespace ipl\Web\Compat;
4
5 use Icinga\Application\Icinga;
6 use Icinga\Application\Version;
7 use Icinga\Util\Csp;
8 use ipl\Web\Style;
9
10 /**
11 * Use this class to define inline style which is compatible
12 * with Icinga Web &lt; 2.12 and with CSP support in &gt;= 2.12
13 */
14 class StyleWithNonce extends Style
15 {
16 public function getNonce(): ?string
17 {
18 if ($this->nonce === null) {
19 $this->nonce = '';
20 if (version_compare(Version::VERSION, '2.12.0', '>=') && Icinga::app()->isWeb()) {
21 $this->nonce = Csp::getStyleNonce() ?? '';
22 }
23 }
24
25 return parent::getNonce();
26 }
27 }