Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,6 @@ function rename_map(array $renames): RenameMapEntryStrategy
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
function bool_entry(string $name, ?bool $value, ?Metadata $metadata = null): Entry
{
if ($value === null) {
return new BooleanEntry($name, null, $metadata);
}

return new BooleanEntry($name, $value, $metadata);
}

Expand Down Expand Up @@ -740,10 +736,6 @@ function date_entry(string $name, DateTimeInterface|string|null $value, ?Metadat
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
function int_entry(string $name, ?int $value, ?Metadata $metadata = null): Entry
{
if ($value === null) {
return new IntegerEntry($name, null, $metadata);
}

return new IntegerEntry($name, $value, $metadata);
}

Expand All @@ -762,10 +754,6 @@ function integer_entry(string $name, ?int $value, ?Metadata $metadata = null): E
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
function enum_entry(string $name, ?UnitEnum $enum, ?Metadata $metadata = null): Entry
{
if ($enum === null) {
return new EnumEntry($name, null, $metadata);
}

return new EnumEntry($name, $enum, $metadata);
}

Expand Down Expand Up @@ -845,10 +833,6 @@ function json_object_entry(string $name, array|string|Json|null $data, ?Metadata
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
function str_entry(string $name, ?string $value, ?Metadata $metadata = null): Entry
{
if ($value === null) {
return new StringEntry($name, null, $metadata);
}

return new StringEntry($name, $value, $metadata);
}

Expand Down Expand Up @@ -1015,10 +999,6 @@ function struct_entry(string $name, ?array $value, Type $type, ?Metadata $metada
));
}

if ($value === null) {
return new StructureEntry($name, null, $type, $metadata);
}

return new StructureEntry($name, $value, $type, $metadata);
}

Expand All @@ -1042,10 +1022,6 @@ function structure_entry(string $name, ?array $value, Type $type, ?Metadata $met
));
}

if ($value === null) {
return new StructureEntry($name, null, $type, $metadata);
}

return new StructureEntry($name, $value, $type, $metadata);
}

Expand All @@ -1067,10 +1043,6 @@ function list_entry(string $name, ?array $value, Type $type, ?Metadata $metadata
));
}

if ($value === null) {
return new ListEntry($name, null, $type, $metadata);
}

return new ListEntry($name, $value, $type, $metadata);
}

Expand All @@ -1092,10 +1064,6 @@ function map_entry(string $name, ?array $value, Type $mapType, ?Metadata $metada
));
}

if ($value === null) {
return new MapEntry($name, null, $mapType, $metadata);
}

return new MapEntry($name, $value, $mapType, $metadata);
}

Expand Down
135 changes: 39 additions & 96 deletions src/core/etl/src/Flow/ETL/Row/EntryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Exception\SchemaDefinitionNotFoundException;
use Flow\ETL\Row\Entry\ListEntry;
use Flow\ETL\Row\Entry\MapEntry;
use Flow\ETL\Row\Entry\StringEntry;
use Flow\ETL\Row\Entry\StructureEntry;
use Flow\ETL\Schema;
use Flow\ETL\Schema\Definition;
use Flow\ETL\Schema\Metadata;
Expand Down Expand Up @@ -54,8 +51,10 @@
use function Flow\ETL\DSL\json_object_entry;
use function Flow\ETL\DSL\list_entry;
use function Flow\ETL\DSL\map_entry;
use function Flow\ETL\DSL\null_entry;
use function Flow\ETL\DSL\string_entry;
use function Flow\ETL\DSL\struct_entry;
use function Flow\ETL\DSL\structure_entry;
use function Flow\ETL\DSL\time_entry;
use function Flow\ETL\DSL\uuid_entry;
use function Flow\ETL\DSL\xml_element_entry;
Expand Down Expand Up @@ -139,7 +138,7 @@ public function createAs(string $entryName, mixed $value, Type $type, ?Metadata
DateType::class => date_entry($entryName, null, $metadata),
EnumType::class => enum_entry($entryName, null, $metadata),
ArrayType::class, JsonType::class => json_entry($entryName, null, $metadata),
NullType::class => StringEntry::fromNull($entryName, $metadata),
NullType::class => null_entry($entryName, $metadata),
XMLType::class => xml_entry($entryName, null, $metadata),
XMLElementType::class => xml_element_entry($entryName, null, $metadata),
HTMLType::class => html_entry($entryName, null, $metadata),
Expand Down Expand Up @@ -169,52 +168,6 @@ public function createAs(string $entryName, mixed $value, Type $type, ?Metadata
$type = $this->typeResolver->fromUnion($type, $value, $entryName);
}

if ($type instanceof StringType) {
return string_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof IntegerType) {
return int_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof BooleanType) {
return bool_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof FloatType) {
return float_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof UuidType) {
return uuid_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof DateType) {
return date_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof TimeType) {
return time_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof DateTimeType) {
return datetime_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof TimeZoneType) {
return string_entry($entryName, type_optional(type_string())->cast($value), $metadata);
}

if ($type instanceof NullType) {
return StringEntry::fromNull($entryName, $metadata);
}

if ($type instanceof EnumType) {
$castValue = type_optional($type)->cast($value);

return enum_entry($entryName, $castValue, $metadata);
}

if ($type instanceof JsonType) {
try {
return json_object_entry($entryName, type_optional($type)->cast($value), $metadata);
Expand All @@ -223,49 +176,43 @@ public function createAs(string $entryName, mixed $value, Type $type, ?Metadata
}
}

if ($type instanceof HTMLType) {
return html_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof HTMLElementType) {
return html_element_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof XMLType) {
return xml_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof XMLElementType) {
return xml_element_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof ArrayType) {
return json_entry($entryName, type_optional($type)->cast($value), $metadata);
}

if ($type instanceof InstanceOfType) {
throw new InvalidArgumentException(
return match ($type::class) {
StringType::class => string_entry($entryName, type_optional($type)->cast($value), $metadata),
IntegerType::class => int_entry($entryName, type_optional($type)->cast($value), $metadata),
BooleanType::class => bool_entry($entryName, type_optional($type)->cast($value), $metadata),
FloatType::class => float_entry($entryName, type_optional($type)->cast($value), $metadata),
UuidType::class => uuid_entry($entryName, type_optional($type)->cast($value), $metadata),
DateType::class => date_entry($entryName, type_optional($type)->cast($value), $metadata),
TimeType::class => time_entry($entryName, type_optional($type)->cast($value), $metadata),
DateTimeType::class => datetime_entry($entryName, type_optional($type)->cast($value), $metadata),
TimeZoneType::class => string_entry($entryName, type_optional(type_string())->cast($value), $metadata),
NullType::class => null_entry($entryName, $metadata),
EnumType::class => enum_entry($entryName, type_optional($type)->cast($value), $metadata),
HTMLType::class => html_entry($entryName, type_optional($type)->cast($value), $metadata),
HTMLElementType::class => html_element_entry($entryName, type_optional($type)->cast($value), $metadata),
XMLType::class => xml_entry($entryName, type_optional($type)->cast($value), $metadata),
XMLElementType::class => xml_element_entry($entryName, type_optional($type)->cast($value), $metadata),
ArrayType::class => json_entry($entryName, type_optional($type)->cast($value), $metadata),
MapType::class => map_entry($entryName, $value === null ? null : $type->cast($value), $type, $metadata),
StructureType::class => structure_entry(
$entryName,
$value === null ? null : $type->cast($value),
$type,
$metadata,
),
ListType::class => list_entry(
$entryName,
$value === null ? null : array_values($type->cast($value)),
$type,
$metadata,
),
InstanceOfType::class => throw new InvalidArgumentException(
"{$entryName}: {$type->toString()} can't be converted to any known Entry, please normalize that object first.",
);
}

if ($type instanceof MapType) {
$processedValue = $value === null ? null : $type->cast($value);

return new MapEntry($entryName, $processedValue, $type, $metadata);
}

if ($type instanceof StructureType) {
$processedValue = $value === null ? null : $type->cast($value);

return new StructureEntry($entryName, $processedValue, $type, $metadata);
}

if ($type instanceof ListType) {
$processedValue = $value === null ? null : array_values($type->cast($value));

return new ListEntry($entryName, $processedValue, $type, $metadata);
}
),
default => throw new InvalidArgumentException(
"Can't convert " . get_debug_type($value) . " value into type \"{$type->toString()}\"",
),
};

// @mago-ignore analysis:avoid-catching-error
} catch (InvalidArgumentException|CastingException|TypeError $e) {
Expand All @@ -274,9 +221,5 @@ public function createAs(string $entryName, mixed $value, Type $type, ?Metadata
previous: $e,
);
}

throw new InvalidArgumentException(
"Can't convert " . get_debug_type($value) . " value into type \"{$type->toString()}\"",
);
}
}
2 changes: 1 addition & 1 deletion web/landing/resources/dsl.json

Large diffs are not rendered by default.

Loading