Skip to content

Commit fb833a9

Browse files
committed
Adjust DOM-related functions to work with HTML
1 parent 4a4b74c commit fb833a9

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ public function __construct(
1818

1919
public function eval(Row $row) : ?string
2020
{
21-
$node = (new Parameter($this->domElement))->as(
22-
$row,
21+
$types = [
2322
type_instance_of(\DOMNode::class),
2423
type_list(type_instance_of(\DOMNode::class)),
25-
type_instance_of(HTMLElement::class),
26-
type_list(type_instance_of(HTMLElement::class))
24+
];
25+
26+
if (\class_exists('\Dom\HTMLElement')) {
27+
$types[] = type_instance_of(HTMLElement::class);
28+
$types[] = type_list(type_instance_of(HTMLElement::class));
29+
}
30+
31+
$node = (new Parameter($this->domElement))->as(
32+
$row,
33+
...$types
2734
);
2835

2936
if ($node instanceof \DOMDocument) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ public function __construct(private readonly ScalarFunction|\DOMNode|HTMlElement
1616

1717
public function eval(Row $row) : ?int
1818
{
19-
$domElement = (new Parameter($this->domElement))->as($row, type_instance_of(\DOMElement::class), type_instance_of(HTMlElement::class));
19+
$types = [
20+
type_instance_of(\DOMNode::class),
21+
];
22+
23+
if (\class_exists('\Dom\HTMLElement')) {
24+
$types[] = type_instance_of(HTMLElement::class);
25+
}
26+
27+
$domElement = (new Parameter($this->domElement))->as($row, ...$types);
2028

2129
if ($domElement === null) {
2230
return null;

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ public function __construct(private readonly ScalarFunction|\DOMNode|HTMLElement
1616

1717
public function eval(Row $row) : mixed
1818
{
19-
$node = (new Parameter($this->node))->as(
20-
$row,
19+
$types = [
2120
type_instance_of(\DOMNode::class),
2221
type_list(type_instance_of(\DOMNode::class)),
23-
type_instance_of(HTMLElement::class),
24-
type_list(type_instance_of(HTMLElement::class))
22+
];
23+
24+
if (\class_exists('\Dom\HTMLElement')) {
25+
$types[] = type_instance_of(HTMLElement::class);
26+
$types[] = type_list(type_instance_of(HTMLElement::class));
27+
}
28+
29+
$node = (new Parameter($this->node))->as(
30+
$row,
31+
...$types
2532
);
2633

2734
if (\is_array($node) && \count($node)) {

0 commit comments

Comments
 (0)