Skip to content

Commit 7e26412

Browse files
committed
Add a new HTMLType
1 parent a6a307f commit 7e26412

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

src/core/etl/src/Flow/ETL/Row/EntryFactory.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ enum_entry,
1414
json_object_entry,
1515
list_entry,
1616
map_entry,
17+
str_entry,
1718
string_entry,
1819
struct_entry,
1920
time_entry,
2021
uuid_entry,
2122
xml_element_entry,
2223
xml_entry};
23-
use function Flow\Types\DSL\{
24+
use function Flow\Types\DSL\{type_date,
25+
type_datetime,
2426
type_html,
2527
type_json,
2628
type_optional,
2729
type_string,
30+
type_time,
2831
type_uuid,
29-
type_xml
30-
};
32+
type_xml,
33+
type_xml_element};
3134
use Flow\ETL\Exception\{InvalidArgumentException,
3235
RuntimeException,
3336
SchemaDefinitionNotFoundException};
@@ -61,6 +64,7 @@ enum_entry,
6164
};
6265
use Flow\Types\Type\Native\String\StringTypeChecker;
6366
use Flow\Types\Type\TypeDetector;
67+
use Flow\Types\Value\Uuid;
6468

6569
final readonly class EntryFactory
6670
{
@@ -106,6 +110,30 @@ public function create(string $entryName, mixed $value, Schema|Definition|null $
106110
}
107111
}
108112

113+
if ($valueType instanceof InstanceOfType) {
114+
if ($valueType->class === \DOMDocument::class) {
115+
$valueType = type_xml();
116+
} elseif ($valueType->class === \DOMElement::class) {
117+
$valueType = type_xml_element();
118+
} elseif ($valueType->class === \DateInterval::class) {
119+
$valueType = type_time();
120+
} elseif (\in_array($valueType->class, [\DateTimeImmutable::class, \DateTimeInterface::class, \DateTime::class], true)) {
121+
if ($value instanceof \DateTimeInterface && $value->format('H:i:s') === '00:00:00') {
122+
$valueType = type_date();
123+
} else {
124+
$valueType = type_datetime();
125+
}
126+
} else {
127+
foreach (['Ramsey\Uuid\UuidInterface', Uuid::class, 'Symfony\Component\Uid\Uuid'] as $uuidClass) {
128+
if (\is_a($valueType->class, $uuidClass, true)) {
129+
$valueType = type_uuid();
130+
131+
break;
132+
}
133+
}
134+
}
135+
}
136+
109137
return $this->createAs($entryName, $value, $valueType);
110138
}
111139

@@ -128,7 +156,7 @@ public function createAs(string $entryName, mixed $value, Definition|Type $defin
128156

129157
if (null === $value && $type instanceof OptionalType) {
130158
return match ($type->base()::class) {
131-
StringType::class => string_entry($entryName, null, $metadata),
159+
StringType::class => str_entry($entryName, null, $metadata),
132160
IntegerType::class => int_entry($entryName, null, $metadata),
133161
FloatType::class => float_entry($entryName, null, $metadata),
134162
BooleanType::class => bool_entry($entryName, null, $metadata),
@@ -158,7 +186,7 @@ public function createAs(string $entryName, mixed $value, Definition|Type $defin
158186
}
159187

160188
if ($type instanceof StringType) {
161-
return string_entry($entryName, type_optional($type)->cast($value), $metadata);
189+
return str_entry($entryName, type_optional($type)->cast($value), $metadata);
162190
}
163191

164192
if ($type instanceof IntegerType) {

0 commit comments

Comments
 (0)