‪TYPO3CMS  ‪main
HtmlDumper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\CMS\Frontend\Html\HtmlWorker;
23 
29 final class ‪HtmlDumper extends \Symfony\Component\VarDumper\Dumper\HtmlDumper
30 {
31  protected ?‪ConsumableNonce ‪$nonce = null;
32 
33  public function ‪setNonce(‪ConsumableNonce ‪$nonce): void
34  {
35  $this->nonce = ‪$nonce;
36  $this->dumpSuffix = str_replace(
37  '<script>',
38  sprintf('<script nonce="%s">', htmlspecialchars(‪$nonce->‪consume())),
39  $this->dumpSuffix
40  );
41  }
42 
46  protected function ‪getDumpHeader(): string
47  {
48  if ($this->dumpHeader !== null) {
49  return $this->dumpHeader;
50  }
51  $dumpHeader = parent::getDumpHeader();
52  if ($this->nonce === null) {
53  return $dumpHeader;
54  }
55  $worker = GeneralUtility::makeInstance(HtmlWorker::class)
56  ->parse($dumpHeader)
57  ->addNonceAttribute($this->nonce, 'script', 'style');
58  $this->dumpHeader = (string)$worker;
59  return $this->dumpHeader;
60  }
61 }
‪TYPO3\CMS\Adminpanel\Utility
Definition: HtmlDumper.php:18
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\ConsumableNonce
Definition: ConsumableNonce.php:24
‪TYPO3\CMS\Adminpanel\Utility\HtmlDumper\$nonce
‪ConsumableNonce $nonce
Definition: HtmlDumper.php:31
‪TYPO3\CMS\Adminpanel\Utility\HtmlDumper
Definition: HtmlDumper.php:30
‪TYPO3\CMS\Core\Domain\ConsumableString\consume
‪consume()
Definition: ConsumableString.php:48
‪TYPO3\CMS\Adminpanel\Utility\HtmlDumper\getDumpHeader
‪getDumpHeader()
Definition: HtmlDumper.php:46
‪TYPO3\CMS\Adminpanel\Utility\HtmlDumper\setNonce
‪setNonce(ConsumableNonce $nonce)
Definition: HtmlDumper.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52