File tree Expand file tree Collapse file tree
core/etl/src/Flow/ETL/Function
lib/types/src/Flow/Types/Type Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1313 */
1414final 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
Original file line number Diff line number Diff line change 1717 type_uuid ,
1818 type_xml };
1919use Flow \Types \Type ;
20+ use Flow \Types \Type \Logical \HTMLType ;
2021use Flow \Types \Type \TypeNarrower ;
2122use 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 /**
You can’t perform that action at this time.
0 commit comments