-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathArrayFormatter.php
More file actions
64 lines (53 loc) · 1.5 KB
/
ArrayFormatter.php
File metadata and controls
64 lines (53 loc) · 1.5 KB
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
<?php
declare(strict_types=1);
namespace Crell\Serde\Formatter;
use Crell\Serde\Attributes\ClassSettings;
use Crell\Serde\Attributes\Field;
use Crell\Serde\Deserializer;
class ArrayFormatter implements Formatter, Deformatter, SupportsCollecting, SupportsTypeIntrospection
{
use ArrayBasedFormatter;
use ArrayBasedDeformatter;
public function format(): string
{
return 'array';
}
/**
* @return array<string, mixed>
*/
public function serializeInitialize(ClassSettings $classDef, Field $rootField): array
{
return ['root' => []];
}
public function serializeFinalize(mixed $runningValue, ClassSettings $classDef): mixed
{
return $runningValue['root'];
}
/**
* @param mixed $source
* The deformatter-specific source value being passed around.
* @param string[] $used
* A list of property names have have already been extracted, and so are
* not "remaining."
* @return array<string, mixed>
*/
public function getRemainingData(mixed $source, array $used): array
{
return array_diff_key($source, array_flip($used));
}
/**
* @return array<string, mixed>
*/
public function deserializeInitialize(
mixed $serialized,
ClassSettings $classDef,
Field $rootField,
Deserializer $deserializer
): array
{
return ['root' => $serialized ?: []];
}
public function deserializeFinalize(mixed $decoded): void
{
}
}