‪TYPO3CMS  ‪main
ContentSecurityPolicyDirective.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 
26 {
27  protected const ‪RULE_PATTERN = '#(?:\'(?<instruction>[^\']+)\')|(?<source>[^\s]+)#';
28 
32  protected ‪$name;
33 
37  protected ‪$instructions = [];
38 
42  protected ‪$sources = [];
43 
44  public function ‪__construct(string ‪$name, string $rule)
45  {
46  $this->name = ‪$name;
47  if (preg_match_all(self::RULE_PATTERN, $rule, $matches)) {
48  foreach (array_keys($matches[0]) as $index) {
49  if ($matches['instruction'][$index] !== '') {
50  $this->instructions[] = $matches['instruction'][$index];
51  } elseif ($matches['source'][$index] !== '') {
52  $this->sources[] = $matches['source'][$index];
53  }
54  }
55  }
56  }
57 
58  public function ‪getName(): string
59  {
60  return ‪$this->name;
61  }
62 
66  public function ‪getInstructions(): array
67  {
69  }
70 
74  public function ‪getSources(): array
75  {
77  }
78 
79  public function ‪hasInstructions(string ...‪$instructions): bool
80  {
81  return array_intersect($this->instructions, ‪$instructions) !== [];
82  }
83 }
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\RULE_PATTERN
‪const RULE_PATTERN
Definition: ContentSecurityPolicyDirective.php:27
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective
Definition: ContentSecurityPolicyDirective.php:26
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\hasInstructions
‪hasInstructions(string ... $instructions)
Definition: ContentSecurityPolicyDirective.php:76
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\$sources
‪string[] $sources
Definition: ContentSecurityPolicyDirective.php:39
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\getInstructions
‪string[] getInstructions()
Definition: ContentSecurityPolicyDirective.php:63
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\getName
‪getName()
Definition: ContentSecurityPolicyDirective.php:55
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\$name
‪string $name
Definition: ContentSecurityPolicyDirective.php:31
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\$instructions
‪string[] $instructions
Definition: ContentSecurityPolicyDirective.php:35
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\__construct
‪__construct(string $name, string $rule)
Definition: ContentSecurityPolicyDirective.php:41
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse
Definition: ContentSecurityPolicyDirective.php:18
‪TYPO3\CMS\Install\SystemEnvironment\ServerResponse\ContentSecurityPolicyDirective\getSources
‪string[] getSources()
Definition: ContentSecurityPolicyDirective.php:71