-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchInput.php
More file actions
117 lines (105 loc) · 2.5 KB
/
Copy pathPatchInput.php
File metadata and controls
117 lines (105 loc) · 2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* @author enea dhack <contact@vaened.dev>
* @link https://vaened.dev DevFolio
*/
declare(strict_types=1);
namespace Vaened\DeltaOrchestrator\Patch;
/**
* @template TInput of array<string, mixed>
*/
final readonly class PatchInput
{
/**
* @param TInput $input
*/
public function __construct(
private array $input,
)
{
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
*/
public function string(string $key): StringPatchValue
{
return new StringPatchValue(
present: $this->isPresent($key),
value : $this->value($key),
);
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
*/
public function int(string $key): IntPatchValue
{
return new IntPatchValue(
present: $this->isPresent($key),
value : $this->value($key),
);
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
*/
public function float(string $key): FloatPatchValue
{
return new FloatPatchValue(
present: $this->isPresent($key),
value : $this->value($key),
);
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
*/
public function bool(string $key): BoolPatchValue
{
return new BoolPatchValue(
present: $this->isPresent($key),
value : $this->value($key),
);
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
*/
public function dateTimeImmutable(string $key): DateTimeImmutablePatchValue
{
return new DateTimeImmutablePatchValue(
present: $this->isPresent($key),
value : $this->value($key),
);
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
*/
public function array(string $key): ArrayPatchValue
{
$value = $this->value($key);
return new ArrayPatchValue(
present: $this->isPresent($key),
value : is_array($value) ? $value : null,
);
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
*/
public function isPresent(string $key): bool
{
return array_key_exists($key, $this->input);
}
/**
* @template TKey of key-of<TInput>
* @param TKey $key
* @return TInput[TKey]|null
*/
public function value(string $key): mixed
{
return $this->input[$key] ?? null;
}
}