1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Chubbyphp\Deserialization\Denormalizer; |
6
|
|
|
|
7
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
8
|
|
|
|
9
|
|
|
final class DenormalizerContextBuilder implements DenormalizerContextBuilderInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array|null |
13
|
|
|
*/ |
14
|
|
|
private $allowedAdditionalFields; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @deprecated |
18
|
|
|
* |
19
|
|
|
* @var string[] |
20
|
|
|
*/ |
21
|
|
|
private $groups = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ServerRequestInterface|null |
25
|
|
|
*/ |
26
|
|
|
private $request; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
private $resetMissingFields = false; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
private $attributes = []; |
37
|
|
|
|
38
|
4 |
|
private function __construct() |
39
|
|
|
{ |
40
|
4 |
|
} |
41
|
|
|
|
42
|
|
|
public static function create(): DenormalizerContextBuilderInterface |
43
|
|
|
{ |
44
|
|
|
return new self(); |
45
|
4 |
|
} |
46
|
|
|
|
47
|
4 |
|
public function setAllowedAdditionalFields( |
48
|
|
|
array $allowedAdditionalFields = null |
49
|
|
|
): DenormalizerContextBuilderInterface { |
50
|
|
|
$this->allowedAdditionalFields = $allowedAdditionalFields; |
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
/** |
56
|
|
|
* @deprecated |
57
|
|
|
* |
58
|
1 |
|
* @param string[] $groups |
59
|
|
|
*/ |
60
|
1 |
|
public function setGroups(array $groups): DenormalizerContextBuilderInterface |
61
|
|
|
{ |
62
|
|
|
$this->groups = $groups; |
|
|
|
|
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function setRequest(ServerRequestInterface $request = null): DenormalizerContextBuilderInterface |
68
|
|
|
{ |
69
|
|
|
$this->request = $request; |
70
|
1 |
|
|
71
|
|
|
return $this; |
72
|
1 |
|
} |
73
|
|
|
|
74
|
1 |
|
/** |
75
|
|
|
* @deprecated |
76
|
|
|
*/ |
77
|
|
|
public function setResetMissingFields(bool $resetMissingFields): DenormalizerContextBuilderInterface |
78
|
|
|
{ |
79
|
|
|
@trigger_error( |
80
|
|
|
'setResetMissingFields is broken by design, please do this your self by model or repository', |
81
|
|
|
E_USER_DEPRECATED |
82
|
2 |
|
); |
83
|
|
|
|
84
|
2 |
|
$this->resetMissingFields = $resetMissingFields; |
85
|
|
|
|
86
|
2 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function setAttributes(array $attributes): DenormalizerContextBuilderInterface |
90
|
|
|
{ |
91
|
|
|
$this->attributes = $attributes; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
public function getContext(): DenormalizerContextInterface |
97
|
|
|
{ |
98
|
1 |
|
return new DenormalizerContext( |
99
|
1 |
|
$this->allowedAdditionalFields, |
100
|
1 |
|
$this->groups, |
|
|
|
|
101
|
|
|
$this->request, |
102
|
|
|
$this->resetMissingFields, |
103
|
1 |
|
$this->attributes |
104
|
|
|
); |
105
|
1 |
|
} |
106
|
|
|
} |
107
|
|
|
|