forked from Crell/Serde
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for forcing Sequences and Dicts to be scalar arrays when …
…deserializing.
- Loading branch information
Showing
7 changed files
with
143 additions
and
14 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde; | ||
|
||
use function Crell\fp\all; | ||
|
||
enum ValueType | ||
{ | ||
case String; | ||
case Int; | ||
case Float; | ||
case Array; | ||
|
||
/** | ||
* @param array<mixed> $values | ||
*/ | ||
public function assert(array $values): bool | ||
{ | ||
return match ($this) { | ||
self::String => all(is_string(...))($values), | ||
self::Int => all(is_int(...))($values), | ||
self::Float => all(is_float(...))($values), | ||
self::Array => all(is_array(...))($values), | ||
}; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Records; | ||
|
||
use Crell\Serde\Attributes\DictionaryField; | ||
use Crell\Serde\Attributes\SequenceField; | ||
use Crell\Serde\KeyType; | ||
use Crell\Serde\ValueType; | ||
|
||
class ScalarArrays | ||
{ | ||
public function __construct( | ||
#[SequenceField(arrayType: ValueType::Int)] | ||
public array $ints, | ||
|
||
#[SequenceField(arrayType: ValueType::Float)] | ||
public array $floats, | ||
|
||
#[DictionaryField(keyType: KeyType::String, arrayType: ValueType::String)] | ||
public array $stringMap, | ||
|
||
#[DictionaryField(keyType: KeyType::String, arrayType: ValueType::Array)] | ||
public array $arrayMap, | ||
) {} | ||
} |
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