Skip to content

Commit 35cf84f

Browse files
committed
Add a new HTMLElementEntry & related stuff
1 parent 0428833 commit 35cf84f

4 files changed

Lines changed: 11 additions & 18 deletions

File tree

src/core/etl/src/Flow/ETL/Function/HTMLQuerySelector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717

1818
public function eval(Row $row) : ?Element
1919
{
20-
if (\PHP_VERSION_ID < 80400) {
20+
if (!\class_exists('\Dom\HTMLDocument')) {
2121
throw new \RuntimeException('This function requires \Dom\HTMLDocument extension available in PHP 8.4+.');
2222
}
2323

src/core/etl/src/Flow/ETL/Function/HTMLQuerySelectorAll.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
*/
2121
public function eval(Row $row) : ?array
2222
{
23-
if (\PHP_VERSION_ID < 80400) {
23+
if (!\class_exists('\Dom\HTMLDocument')) {
2424
throw new \RuntimeException('This function requires \Dom\HTMLDocument extension available in PHP 8.4+.');
2525
}
2626

src/lib/types/src/Flow/Types/Type/Logical/HTMLType.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
final readonly class HTMLType implements Type
1515
{
16-
private const HTML_ALIKE_REGEX = <<<'REGXP'
16+
public const HTML_ALIKE_REGEX = <<<'REGXP'
1717
@^
1818
<!DOCTYPE\s+html[^>]*>\s* # must start with <!DOCTYPE html ...>
1919
<html[^>]*>\s* # opening <html>
@@ -49,23 +49,11 @@ public function cast(mixed $value) : HTMLDocument
4949
public function isValid(mixed $value) : bool
5050
{
5151
// \Dom\HTMLDocument exist in PHP 8.4+
52-
if (\PHP_VERSION_ID < 80400) {
52+
if (!\class_exists('\Dom\HTMLDocument')) {
5353
return false;
5454
}
5555

56-
if (!\is_string($value)) {
57-
return $value instanceof HTMLDocument;
58-
}
59-
60-
if ('' === $value) {
61-
return false;
62-
}
63-
64-
if ('<' !== $value[0]) {
65-
return false;
66-
}
67-
68-
return \preg_match(self::HTML_ALIKE_REGEX, $value) === 1;
56+
return $value instanceof HTMLDocument;
6957
}
7058

7159
public function normalize() : array

src/lib/types/src/Flow/Types/Type/Native/String/StringTypeNarrower.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
type_uuid,
1818
type_xml};
1919
use Flow\Types\Type;
20+
use Flow\Types\Type\Logical\HTMLType;
2021
use Flow\Types\Type\TypeNarrower;
2122
use Flow\Types\Value\Uuid;
2223

@@ -166,7 +167,11 @@ private function isFloat(string $value) : bool
166167
*/
167168
private function isHTML(string $value) : bool
168169
{
169-
return type_html()->isValid($value);
170+
if ('<' !== $value[0]) {
171+
return false;
172+
}
173+
174+
return \preg_match(HTMLType::HTML_ALIKE_REGEX, $value) === 1;
170175
}
171176

172177
/**

0 commit comments

Comments
 (0)