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
49 changes: 38 additions & 11 deletions src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,36 @@

namespace Flow\ETL\DSL;

use function Flow\Types\DSL\{is_nullable as is_nullable_new, type_array as type_array_new, type_boolean as type_boolean_new, type_callable as type_callable_new, type_date as type_date_new, type_datetime as type_datetime_new, type_enum as type_enum_new, type_equals as type_equals_new, type_float as type_float_new, type_from_array as type_from_array_new, type_instance_of as type_instance_of_new, type_integer as type_integer_new, type_is as type_is_new, type_is_any as type_is_any_new, type_json as type_json_new, type_list as type_list_new, type_map as type_map_new, type_null as type_null_new, type_optional as type_optional_new, type_resource as type_resource_new, type_string as type_string_new, type_structure as type_structure_new, type_time as type_time_new, type_union as type_union_new, type_uuid as type_uuid_new, type_xml as type_xml_new, type_xml_element as type_xml_element_new, types as types_new};
use function Flow\Types\DSL\{dom_element_to_string as dom_element_to_string_new,
get_type as get_type_new,
is_nullable as is_nullable_new,
type_array as type_array_new,
type_boolean as type_boolean_new,
type_callable as type_callable_new,
type_date as type_date_new,
type_datetime as type_datetime_new,
type_enum as type_enum_new,
type_equals as type_equals_new,
type_float as type_float_new,
type_from_array as type_from_array_new,
type_instance_of as type_instance_of_new,
type_integer as type_integer_new,
type_is as type_is_new,
type_is_any as type_is_any_new,
type_json as type_json_new,
type_list as type_list_new,
type_map as type_map_new,
type_null as type_null_new,
type_optional as type_optional_new,
type_resource as type_resource_new,
type_string as type_string_new,
type_structure as type_structure_new,
type_time as type_time_new,
type_union as type_union_new,
type_uuid as type_uuid_new,
type_xml as type_xml_new,
type_xml_element as type_xml_element_new,
types as types_new};
use Flow\Calculator\Rounding;
use Flow\ETL\{
Analyze,
Expand Down Expand Up @@ -158,7 +187,7 @@
StringType,
UnionType
};
use Flow\Types\Type\{Type, TypeDetector, Types};
use Flow\Types\Type\{Type, Types};
use UnitEnum;

/**
Expand Down Expand Up @@ -1721,11 +1750,13 @@ function append() : SaveMode

/**
* @return Type<mixed>
*
* @deprecated Please use \Flow\Types\DSL\get_type($value) instead
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
function get_type(mixed $value) : Type
{
return (new TypeDetector())->detectType($value);
return get_type_new($value);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::SCHEMA)]
Expand Down Expand Up @@ -1901,17 +1932,13 @@ function random_string(
return new RandomString($length, $generator);
}

/**
* @deprecated Please use \Flow\Types\DSL\dom_element_to_string() instead
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
function dom_element_to_string(\DOMElement $element, bool $format_output = false, bool $preserver_white_space = false) : string|false
{
$doc = new \DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = $format_output;
$doc->preserveWhiteSpace = $preserver_white_space;

$importedNode = $doc->importNode($element, true);
$doc->appendChild($importedNode);

return $doc->saveXML($doc->documentElement);
return dom_element_to_string_new($element, $format_output, $preserver_white_space);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
Expand Down
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Flow\ETL\Function;

use function Flow\Types\DSL\{type_array, type_boolean, type_date, type_datetime, type_float, type_instance_of, type_integer, type_json, type_string, type_xml};
use Flow\ETL\Exception\{CastingException, InvalidArgumentException};
use Flow\ETL\Exception\{InvalidArgumentException};
use Flow\ETL\Function\ScalarFunction\ScalarResult;
use Flow\ETL\Row;
use Flow\Types\Exception\CastingException;
use Flow\Types\Type\{Type};

final class Cast extends ScalarFunctionChain
Expand Down
4 changes: 2 additions & 2 deletions src/core/etl/src/Flow/ETL/Row/EntryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ enum_entry,
xml_element_entry,
xml_entry};
use function Flow\Types\DSL\{type_boolean, type_date, type_datetime, type_float, type_integer, type_json, type_optional, type_string, type_time, type_uuid, type_xml, type_xml_element};
use Flow\ETL\Exception\{CastingException,
InvalidArgumentException,
use Flow\ETL\Exception\{InvalidArgumentException,
RuntimeException,
SchemaDefinitionNotFoundException};
use Flow\ETL\Row\Entry\{ListEntry, StringEntry};
use Flow\ETL\Schema;
use Flow\ETL\Schema\{Definition, Metadata};
use Flow\Types\Exception\CastingException;
use Flow\Types\Type\Logical\{DateTimeType,
DateType,
InstanceOfType,
Expand Down
38 changes: 37 additions & 1 deletion src/lib/types/src/Flow/Types/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
namespace Flow\Types\DSL;

use Flow\ETL\Attribute\{DocumentationDSL, Module, Type as DSLType};
use Flow\Types\Type\{Comparator, Type, TypeFactory, Types};
use Flow\Types\Type\{Comparator, Type, TypeDetector, TypeFactory, Types};
use Flow\Types\Type\Logical\{DateTimeType,
DateType,
InstanceOfType,
JsonType,
ListType,
MapType,
NonEmptyStringType,
OptionalType,
PositiveIntegerType,
ScalarType,
StructureType,
TimeType,
Expand Down Expand Up @@ -274,6 +276,18 @@ function type_null() : NullType
return new NullType();
}

#[DocumentationDSL(module: Module::TYPES, type: DSLType::TYPE)]
function type_positive_integer() : PositiveIntegerType
{
return new PositiveIntegerType();
}

#[DocumentationDSL(module: Module::TYPES, type: DSLType::TYPE)]
function type_non_empty_string() : NonEmptyStringType
{
return new NonEmptyStringType();
}

/**
* @template T of UnitEnum
*
Expand Down Expand Up @@ -311,3 +325,25 @@ function type_is_any(Type $type, string $typeClass, string ...$typeClasses) : bo
{
return (new Comparator())->isAny($type, $typeClass, ...$typeClasses);
}

/**
* @return Type<mixed>
*/
#[DocumentationDSL(module: Module::TYPES, type: DSLType::HELPER)]
function get_type(mixed $value) : Type
{
return (new TypeDetector())->detectType($value);
}

#[DocumentationDSL(module: Module::TYPES, type: DSLType::HELPER)]
function dom_element_to_string(\DOMElement $element, bool $format_output = false, bool $preserver_white_space = false) : string|false
{
$doc = new \DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = $format_output;
$doc->preserveWhiteSpace = $preserver_white_space;

$importedNode = $doc->importNode($element, true);
$doc->appendChild($importedNode);

return $doc->saveXML($doc->documentElement);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Flow\ETL\Exception;
namespace Flow\Types\Exception;

use Flow\Types\Type\Type;

Expand Down
9 changes: 9 additions & 0 deletions src/lib/types/src/Flow/Types/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Flow\Types\Exception;

class Exception extends \Exception
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Flow\Types\Exception;

class InvalidArgumentException extends Exception
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Flow\ETL\Exception;
namespace Flow\Types\Exception;

use Flow\Types\Type\{Type, TypeDetector};

Expand Down
9 changes: 9 additions & 0 deletions src/lib/types/src/Flow/Types/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Flow\Types\Exception;

class RuntimeException extends Exception
{
}
4 changes: 2 additions & 2 deletions src/lib/types/src/Flow/Types/Type/ArrayContentDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Flow\Types\Type;

use function Flow\Types\DSL\{type_array, type_null, type_optional, type_string};
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\Types\Exception\InvalidArgumentException;
use Flow\Types\Type\Native\{IntegerType, NullType, StringType};

final readonly class ArrayContentDetector
Expand Down Expand Up @@ -35,7 +35,7 @@ public function __construct(Types $uniqueKeysType, private Types $uniqueValuesTy
public function firstKeyType() : IntegerType|StringType|null
{
if (null !== $this->firstKeyType && (!$this->firstKeyType instanceof IntegerType && !$this->firstKeyType instanceof StringType)) {
throw InvalidArgumentException::because('First unique key type must be of IntegerType or StringType, given: ' . $this->firstKeyType::class);
throw new InvalidArgumentException('First unique key type must be of IntegerType or StringType, given: ' . $this->firstKeyType::class);
}

return $this->firstKeyType;
Expand Down
10 changes: 8 additions & 2 deletions src/lib/types/src/Flow/Types/Type/AutoCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace Flow\Types\Type;

use function Flow\ETL\DSL\{get_type};
use function Flow\Types\DSL\{type_boolean, type_date, type_datetime, type_float, type_integer, type_json, type_uuid};
use function Flow\Types\DSL\{get_type,
type_boolean,
type_date,
type_datetime,
type_float,
type_integer,
type_json,
type_uuid};
use Flow\Types\Type\Native\String\StringTypeChecker;

final readonly class AutoCaster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace Flow\Types\Type\Logical;

use DateTimeInterface;
use Flow\ETL\Exception\{CastingException, InvalidTypeException};
use Flow\Types\Exception\{CastingException};
use Flow\Types\Exception\InvalidTypeException;
use Flow\Types\Type\Type;

/**
Expand Down
9 changes: 7 additions & 2 deletions src/lib/types/src/Flow/Types/Type/Logical/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace Flow\Types\Type\Logical;

use DateTimeInterface;
use Flow\ETL\Exception\{CastingException, InvalidTypeException};
use Flow\Types\Exception\{CastingException};
use Flow\Types\Exception\InvalidTypeException;
use Flow\Types\Type\Type;

/**
Expand Down Expand Up @@ -33,6 +34,11 @@ public function cast(mixed $value) : \DateTimeInterface
}

try {
/** @phpstan-ignore-next-line */
if ($value instanceof \DateTimeImmutable || $value instanceof \DateTime) {
return $value->setTime(0, 0, 0, 0);
}

if (\is_string($value)) {
return (new \DateTimeImmutable($value))->setTime(0, 0, 0, 0);
}
Expand All @@ -48,7 +54,6 @@ public function cast(mixed $value) : \DateTimeInterface

if ($value instanceof \DateInterval) {
return (new \DateTimeImmutable('@0'))->add($value)->setTime(0, 0, 0, 0);

}
} catch (\Throwable) {
throw new CastingException($value, $this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Flow\Types\Type\Logical;

use function Flow\Types\DSL\type_instance_of;
use Flow\ETL\Exception\{CastingException, InvalidArgumentException, InvalidTypeException};
use Flow\Types\Exception\{CastingException, InvalidArgumentException, InvalidTypeException};
use Flow\Types\Type\Type;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/lib/types/src/Flow/Types/Type/Logical/JsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace Flow\Types\Type\Logical;

use function Flow\Types\DSL\type_json;
use Flow\ETL\Exception\{CastingException, InvalidTypeException};
use Flow\Types\Exception\{CastingException};
use Flow\Types\Exception\InvalidTypeException;
use Flow\Types\Type\Native\String\StringTypeChecker;
use Flow\Types\Type\Type;

Expand Down
3 changes: 2 additions & 1 deletion src/lib/types/src/Flow/Types/Type/Logical/ListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace Flow\Types\Type\Logical;

use Flow\ETL\Exception\{CastingException, InvalidTypeException};
use Flow\Types\Exception\{CastingException};
use Flow\Types\Exception\InvalidTypeException;
use Flow\Types\Type\{Type, TypeFactory};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/src/Flow/Types/Type/Logical/MapType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Flow\Types\Type\Logical;

use Flow\ETL\Exception\{CastingException, InvalidArgumentException, InvalidTypeException};
use Flow\Types\Exception\{CastingException, InvalidArgumentException, InvalidTypeException};
use Flow\Types\Type\Native\{IntegerType, StringType};
use Flow\Types\Type\{Type, TypeFactory};

Expand Down
Loading