forked from Crell/Serde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deformatter.php
69 lines (54 loc) · 2.36 KB
/
Deformatter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace Crell\Serde\Formatter;
use Crell\Serde\Attributes\ClassSettings;
use Crell\Serde\Attributes\Field;
use Crell\Serde\Deserializer;
use Crell\Serde\DeformatterResult;
/**
* Decode data from a given format when called by an Importer.
*
* It is this class's responsibility to enforce "strict mode" on each field
* type. That may vary slightly depending on the format. (eg, in XML, everything
* is a string by default so just checking the variable type is not viable.) In
* strict mode, invalid values should throw a TypeMismatch. In weak mode, a
* good faith effort should be made to convert the data to the expected type.
*/
interface Deformatter
{
public function format(): string;
public function rootField(Deserializer $deserializer, string $targetType): Field;
public function deserializeInitialize(
mixed $serialized,
ClassSettings $classDef,
Field $rootField,
Deserializer $deserializer
): mixed;
public function deserializeInt(mixed $decoded, Field $field): int|DeformatterResult;
public function deserializeFloat(mixed $decoded, Field $field): float|DeformatterResult;
public function deserializeBool(mixed $decoded, Field $field): bool|DeformatterResult;
public function deserializeString(mixed $decoded, Field $field): string|DeformatterResult;
public function deserializeNull(mixed $decoded, Field $field): ?DeformatterResult;
/**
* @param mixed $decoded
* @param Field $field
* @param Deserializer $deserializer
* @return mixed[]|DeformatterResult|null
*/
public function deserializeSequence(mixed $decoded, Field $field, Deserializer $deserializer): array|DeformatterResult|null;
/**
* @param mixed $decoded
* @param Field $field
* @param Deserializer $deserializer
* @return array<string|int, mixed>|DeformatterResult|null
*/
public function deserializeDictionary(mixed $decoded, Field $field, Deserializer $deserializer): array|DeformatterResult|null;
/**
* @param mixed $decoded
* @param Field $field
* @param Deserializer $deserializer
* @return array<string, mixed>|DeformatterResult
*/
public function deserializeObject( mixed $decoded, Field $field, Deserializer $deserializer): array|DeformatterResult;
public function deserializeFinalize(mixed $decoded): void;
}