ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ContainsHtmlValidator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Mount;
22
23use DOMDocument;
24use Exception;
25use Throwable;
26use RecursiveIteratorIterator;
28
30{
31 public function __construct(private string $text)
32 {
33 }
34
35 public function isValid(): bool
36 {
37 if (!preg_match('/<[^>]+?>/', $this->text)) {
38 return false;
39 }
40
41 try {
42 $dom = new DOMDocument();
43 if (!$dom->loadHTML($this->text)) {
44 return false;
45 }
46
47 $iter = new RecursiveIteratorIterator(
48 new ilHtmlDomNodeIterator($dom),
49 RecursiveIteratorIterator::SELF_FIRST
50 );
51 foreach ($iter as $element) {
53 if (strtolower((string) $element->nodeName) === 'body') {
54 continue;
55 }
56
57 if ($element->nodeType === XML_ELEMENT_NODE) {
58 return true;
59 }
60 }
61 } catch (Exception | Throwable) {
62 return false;
63 }
64
65 return false;
66 }
67}
Class ilHtmlDomNodeIterator.
$text
Definition: xapiexit.php:21