Skip to content

Commit 192ba6d

Browse files
committed
Add a RequiredPHPVersionException
1 parent 0052cce commit 192ba6d

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\ETL\Exception;
6+
7+
final class RequiredPHPVersionException extends RuntimeException
8+
{
9+
public function __construct(string $className, string $version, ?\Exception $previous = null)
10+
{
11+
parent::__construct(
12+
"To use {$className} class, you need to upgrade your PHP version to: {$version}+.",
13+
previous: $previous
14+
);
15+
}
16+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Flow\ETL\Function;
66

77
use Dom\{Element, HTMLDocument};
8+
use Flow\ETL\Exception\RequiredPHPVersionException;
89
use Flow\ETL\Row;
910

1011
final class HTMLQuerySelector extends ScalarFunctionChain
@@ -18,7 +19,7 @@ public function __construct(
1819
public function eval(Row $row) : ?Element
1920
{
2021
if (!\class_exists('\Dom\HTMLDocument')) {
21-
throw new \RuntimeException('This function requires \Dom\HTMLDocument extension available in PHP 8.4+.');
22+
throw new RequiredPHPVersionException('\Dom\HTMLDocument', '8.4');
2223
}
2324

2425
$value = (new Parameter($this->value))->asInstanceOf($row, HTMLDocument::class);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Flow\ETL\Function;
66

77
use DOM\{Element, HTMLDocument};
8+
use Flow\ETL\Exception\RequiredPHPVersionException;
89
use Flow\ETL\Row;
910

1011
final class HTMLQuerySelectorAll extends ScalarFunctionChain
@@ -21,7 +22,7 @@ public function __construct(
2122
public function eval(Row $row) : ?array
2223
{
2324
if (!\class_exists('\Dom\HTMLDocument')) {
24-
throw new \RuntimeException('This function requires \Dom\HTMLDocument extension available in PHP 8.4+.');
25+
throw new RequiredPHPVersionException('\Dom\HTMLDocument', '8.4');
2526
}
2627

2728
$value = (new Parameter($this->value))->asInstanceOf($row, HTMLDocument::class);

0 commit comments

Comments
 (0)