|
26 | 26 |
|
27 | 27 | class TagAndAttributeRemover
|
28 | 28 | {
|
29 |
| - private DOMDocument $domHtml; |
30 |
| - private array $allowedTags; |
31 |
| - private array $currentTags; |
32 |
| - private array $allowedUrlPrefixes; |
33 | 29 | private static array $urlAttributes = ['href', 'src'];
|
34 | 30 |
|
35 |
| - private function __construct(DOMDocument $domHtml, array $currentTags, array $allowedTags, array $allowedUrlPrefixes) |
| 31 | + private function __construct(private DOMDocument $domHtml, private array $currentTags, private array $allowedTags, private array $allowedUrlPrefixes) |
36 | 32 | {
|
37 |
| - $this->domHtml = $domHtml; |
38 |
| - $this->currentTags = $currentTags; |
39 |
| - $this->allowedTags = $allowedTags; |
40 |
| - $this->allowedUrlPrefixes = $allowedUrlPrefixes; |
41 | 33 | }
|
42 | 34 |
|
43 | 35 | public static function cleanHtml(string $html, string $allowedTagsAndAttributesList, ?string $allowedUrlPrefixes = ''): string
|
@@ -66,7 +58,7 @@ public static function cleanHtml(string $html, string $allowedTagsAndAttributesL
|
66 | 58 |
|
67 | 59 | private static function safeExplodeString(string $delimiter, string $string, ?bool $allowEmptyArrayElement = true): array
|
68 | 60 | {
|
69 |
| - if (strpos($string, $delimiter) !== false) { |
| 61 | + if (str_contains($string, $delimiter)) { |
70 | 62 | return explode($delimiter, $string);
|
71 | 63 | }
|
72 | 64 |
|
@@ -154,7 +146,7 @@ private function removeAttributesWithNotAllowedUrlPrefixes(DOMElement $node, DOM
|
154 | 146 | {
|
155 | 147 | $isAllowed = 0;
|
156 | 148 | foreach ($this->allowedUrlPrefixes as $allowedUrlPrefix) {
|
157 |
| - if (strpos($attribute->nodeValue, $allowedUrlPrefix) === 0) { |
| 149 | + if (str_starts_with($attribute->nodeValue, $allowedUrlPrefix)) { |
158 | 150 | $isAllowed = 1;
|
159 | 151 | break;
|
160 | 152 | }
|
|
0 commit comments