|
4 | 4 |
|
5 | 5 | namespace Flow\Types\Type\Native\String; |
6 | 6 |
|
7 | | -use Dom\HTMLDocument; |
8 | | -use Flow\Types\Value\Uuid; |
| 7 | +use Flow\Types\Value\{HTMLDocument, Uuid}; |
9 | 8 |
|
10 | 9 | final readonly class StringTypeChecker |
11 | 10 | { |
@@ -101,53 +100,12 @@ public function isFloat() : bool |
101 | 100 | return false; |
102 | 101 | } |
103 | 102 |
|
104 | | - // scientific notation |
105 | | - if (\is_numeric($this->string) && (\str_contains($this->string, 'e') || \str_contains($this->string, 'E'))) { |
106 | | - |
107 | | - } |
108 | | - |
109 | 103 | return \is_numeric($this->string) && \str_contains($this->string, '.'); |
110 | 104 | } |
111 | 105 |
|
112 | 106 | public function isHTML() : bool |
113 | 107 | { |
114 | | - if ($this->string === '') { |
115 | | - return false; |
116 | | - } |
117 | | - |
118 | | - if ('<' !== $this->string[0]) { |
119 | | - return false; |
120 | | - } |
121 | | - |
122 | | - if (\preg_match('/(<!doctype(.+?)>)?<html(.+?)>(.+?)<\/html>/im', $this->string) === 1) { |
123 | | - if (\class_exists('\Dom\HTMLDocument', false)) { |
124 | | - $options = \LIBXML_HTML_NOIMPLIED; |
125 | | - |
126 | | - if (defined('Dom\HTML_NO_DEFAULT_NS')) { |
127 | | - $options |= constant('\Dom\HTML_NO_DEFAULT_NS'); |
128 | | - } |
129 | | - |
130 | | - $doc = HTMLDocument::createFromString($this->string, $options); |
131 | | - |
132 | | - return \in_array(\strtolower((string) $doc->documentElement->tagName), ['doctype', 'html', 'html5'], true); |
133 | | - } |
134 | | - |
135 | | - try { |
136 | | - \libxml_use_internal_errors(true); |
137 | | - |
138 | | - $doc = new \DOMDocument(); |
139 | | - $result = @$doc->loadHTML($this->string); |
140 | | - |
141 | | - return (bool) $result; |
142 | | - } catch (\Exception) { |
143 | | - return false; |
144 | | - } finally { |
145 | | - \libxml_clear_errors(); // Clear any errors if needed |
146 | | - \libxml_use_internal_errors(false); // Restore standard error handling |
147 | | - } |
148 | | - } |
149 | | - |
150 | | - return false; |
| 108 | + return HTMLDocument::isValid($this->string); |
151 | 109 | } |
152 | 110 |
|
153 | 111 | public function isInteger() : bool |
|
0 commit comments