-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
201 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/core/etl/src/Flow/ETL/PHP/Type/Logical/LogicalType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\PHP\Type\Logical; | ||
|
||
use Flow\ETL\PHP\Type\Type; | ||
|
||
interface LogicalType extends Type | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Flow\ETL\PHP\Type\Logical\Map; | ||
|
||
use Flow\ETL\PHP\Type\Native\ScalarType; | ||
|
||
final class MapKey | ||
{ | ||
private function __construct(private readonly ScalarType $value) | ||
{ | ||
} | ||
|
||
public static function integer() : self | ||
{ | ||
return new self(ScalarType::integer); | ||
} | ||
|
||
public static function string() : self | ||
{ | ||
return new self(ScalarType::string); | ||
} | ||
|
||
public function isEqual(mixed $value) : bool | ||
{ | ||
return $this->value->isEqual($value); | ||
} | ||
|
||
public function isValid(mixed $value) : bool | ||
{ | ||
return $this->value->isValid($value); | ||
} | ||
|
||
public function toString() : string | ||
{ | ||
return $this->value->toString(); | ||
} | ||
|
||
public function value() : ScalarType | ||
{ | ||
return $this->value; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapValue.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Flow\ETL\PHP\Type\Logical\Map; | ||
|
||
use Flow\ETL\PHP\Type\Native\ObjectType; | ||
use Flow\ETL\PHP\Type\Native\ScalarType; | ||
|
||
final class MapValue | ||
{ | ||
private function __construct(private readonly ScalarType|ObjectType $value) | ||
{ | ||
} | ||
|
||
public static function boolean() : self | ||
{ | ||
return new self(ScalarType::boolean); | ||
} | ||
|
||
public static function float() : self | ||
{ | ||
return new self(ScalarType::float); | ||
} | ||
|
||
public static function integer() : self | ||
{ | ||
return new self(ScalarType::integer); | ||
} | ||
|
||
/** | ||
* @param class-string $class | ||
*/ | ||
public static function object(string $class) : self | ||
{ | ||
return new self(new ObjectType($class)); | ||
} | ||
|
||
public static function scalar(string $value) : self | ||
{ | ||
return new self(ScalarType::fromString($value)); | ||
} | ||
|
||
public static function string() : self | ||
{ | ||
return new self(ScalarType::string); | ||
} | ||
|
||
public function isEqual(mixed $value) : bool | ||
{ | ||
return $this->value->isEqual($value); | ||
} | ||
|
||
public function isValid(mixed $value) : bool | ||
{ | ||
return $this->value->isValid($value); | ||
} | ||
|
||
public function toString() : string | ||
{ | ||
return $this->value->toString(); | ||
} | ||
|
||
public function value() : ScalarType|ObjectType | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Flow\ETL\PHP\Type\Logical; | ||
|
||
use Flow\ETL\PHP\Type\Logical\Map\MapKey; | ||
use Flow\ETL\PHP\Type\Logical\Map\MapValue; | ||
use Flow\ETL\PHP\Type\Type; | ||
use Flow\Serializer\Serializable; | ||
|
||
/** | ||
* @implements Serializable<array{key: MapKey, value: MapValue}> | ||
*/ | ||
final class MapType implements LogicalType, Serializable | ||
{ | ||
public function __construct(private readonly Map\MapKey $key, private readonly Map\MapValue $value) | ||
{ | ||
} | ||
|
||
public function __serialize() : array | ||
{ | ||
return ['key' => $this->key, 'value' => $this->value]; | ||
} | ||
|
||
public function __unserialize(array $data) : void | ||
{ | ||
$this->key = $data['key']; | ||
$this->value = $data['value']; | ||
} | ||
|
||
public function isEqual(Type $type) : bool | ||
{ | ||
if (!$type instanceof self) { | ||
return false; | ||
} | ||
|
||
return $this->key->toString() === $type->key()->toString() && $this->value->toString() === $type->value()->toString(); | ||
} | ||
|
||
public function isValid(mixed $value) : bool | ||
{ | ||
if (!\is_array($value)) { | ||
return false; | ||
} | ||
|
||
foreach ($value as $key => $item) { | ||
if (!$this->key->isValid($key)) { | ||
return false; | ||
} | ||
|
||
if (!$this->value->isValid($item)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function key() : MapKey | ||
{ | ||
return $this->key; | ||
} | ||
|
||
public function toString() : string | ||
{ | ||
return 'map<' . $this->key->toString() . ', ' . $this->value->toString() . '>'; | ||
} | ||
|
||
public function value() : MapValue | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters