summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/web/src/Compat/StyleWithNonce.php
blob: 8c1be31c79e046ce1ef57e20951f0f4a225d863c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

namespace ipl\Web\Compat;

use Icinga\Application\Icinga;
use Icinga\Application\Version;
use Icinga\Util\Csp;
use ipl\Web\Style;

/**
 * Use this class to define inline style which is compatible
 * with Icinga Web &lt; 2.12 and with CSP support in &gt;= 2.12
 */
class StyleWithNonce extends Style
{
    public function getNonce(): ?string
    {
        if ($this->nonce === null) {
            $this->nonce = '';
            if (version_compare(Version::VERSION, '2.12.0', '>=') && Icinga::app()->isWeb()) {
                $this->nonce = Csp::getStyleNonce() ?? '';
            }
        }

        return parent::getNonce();
    }
}