Skip to content

Commit

Permalink
Introduce class ipl\Web\Compat\StyleWithNonce
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Sep 8, 2023
1 parent 1895d76 commit 792af2a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Compat/StyleWithNonce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace ipl\Web\Compat;

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 = version_compare(Version::VERSION, '2.12.0', '>=')
? Csp::getStyleNonce() ?? ''
: '';
}

return parent::getNonce();
}
}

0 comments on commit 792af2a

Please sign in to comment.