1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Maba\Bundle\RestBundle\Entity; |
5
|
|
|
|
6
|
|
|
use RuntimeException; |
7
|
|
|
|
8
|
|
|
class RestRequestOptions |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string|null |
12
|
|
|
*/ |
13
|
|
|
private $bodyDenormalizationType; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string|null |
17
|
|
|
*/ |
18
|
|
|
private $bodyDenormalizationGroup; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string|null |
22
|
|
|
*/ |
23
|
|
|
private $bodyParameterName; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array of string |
27
|
|
|
*/ |
28
|
|
|
private $supportedContentTypes; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
private $jsonEncodedBody; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var bool |
37
|
|
|
*/ |
38
|
|
|
private $bodyOptional; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string|null |
42
|
|
|
*/ |
43
|
|
|
private $responseNormalizationType; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string|null |
47
|
|
|
*/ |
48
|
|
|
private $responseNormalizationGroup; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
private $requiredPermissions; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array|PathAttributeResolverOptions[] |
57
|
|
|
*/ |
58
|
|
|
private $pathAttributeResolverOptionsList; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array|QueryResolverOptions[] |
62
|
|
|
*/ |
63
|
|
|
private $queryResolverOptionsList; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var ValidationOptions|null |
67
|
|
|
*/ |
68
|
|
|
private $bodyValidationOptions; |
69
|
|
|
|
70
|
88 |
|
public function __construct() |
71
|
|
|
{ |
72
|
88 |
|
$this->supportedContentTypes = ['', 'application/json']; |
73
|
88 |
|
$this->jsonEncodedBody = true; |
74
|
88 |
|
$this->bodyOptional = false; |
75
|
88 |
|
$this->requiredPermissions = []; |
76
|
88 |
|
$this->pathAttributeResolverOptionsList = []; |
77
|
88 |
|
$this->queryResolverOptionsList = []; |
78
|
88 |
|
$this->bodyValidationOptions = new ValidationOptions(); |
79
|
88 |
|
} |
80
|
|
|
|
81
|
81 |
|
public function setBodyDenormalizationType(string $bodyDenormalizationType): self |
82
|
|
|
{ |
83
|
81 |
|
$this->bodyDenormalizationType = $bodyDenormalizationType; |
84
|
81 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string|null $bodyDenormalizationGroup |
89
|
|
|
* @return $this |
90
|
|
|
*/ |
91
|
81 |
|
public function setBodyDenormalizationGroup($bodyDenormalizationGroup): self |
92
|
|
|
{ |
93
|
81 |
|
$this->bodyDenormalizationGroup = $bodyDenormalizationGroup; |
94
|
81 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
82 |
|
public function setBodyParameterName(string $bodyParameterName): self |
98
|
|
|
{ |
99
|
82 |
|
$this->bodyParameterName = $bodyParameterName; |
100
|
82 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
81 |
|
public function setSupportedContentTypes(array $supportedContentTypes, bool $jsonEncodedBody = false): self |
104
|
|
|
{ |
105
|
81 |
|
$this->supportedContentTypes = $supportedContentTypes; |
106
|
81 |
|
$this->jsonEncodedBody = $jsonEncodedBody; |
107
|
81 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
81 |
|
public function setBodyOptional(bool $bodyOptional): self |
111
|
|
|
{ |
112
|
81 |
|
$this->bodyOptional = $bodyOptional; |
113
|
81 |
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param string|null $responseNormalizationType |
118
|
|
|
* @return $this |
119
|
|
|
*/ |
120
|
83 |
|
public function setResponseNormalizationType($responseNormalizationType): self |
121
|
|
|
{ |
122
|
83 |
|
$this->responseNormalizationType = $responseNormalizationType; |
123
|
83 |
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param string|null $responseNormalizationGroup |
128
|
|
|
* @return $this |
129
|
|
|
*/ |
130
|
81 |
|
public function setResponseNormalizationGroup($responseNormalizationGroup): self |
131
|
|
|
{ |
132
|
81 |
|
$this->responseNormalizationGroup = $responseNormalizationGroup; |
133
|
81 |
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param array $requiredPermissions array of string |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
82 |
|
public function setRequiredPermissions(array $requiredPermissions): self |
141
|
|
|
{ |
142
|
82 |
|
$this->requiredPermissions = $requiredPermissions; |
143
|
82 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
81 |
|
public function addPathAttributeResolverOptions(PathAttributeResolverOptions $pathAttributeResolverOptions): self |
147
|
|
|
{ |
148
|
81 |
|
$this->pathAttributeResolverOptionsList[] = $pathAttributeResolverOptions; |
149
|
81 |
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
81 |
|
public function addQueryResolverOptions(QueryResolverOptions $queryResolverOptions): self |
153
|
|
|
{ |
154
|
81 |
|
$this->queryResolverOptionsList[] = $queryResolverOptions; |
155
|
81 |
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
81 |
|
public function setBodyValidationOptions(ValidationOptions $bodyValidationOptions): self |
159
|
|
|
{ |
160
|
81 |
|
$this->bodyValidationOptions = $bodyValidationOptions; |
161
|
81 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
93 |
|
public function hasBodyDenormalization(): bool |
165
|
|
|
{ |
166
|
93 |
|
return $this->bodyDenormalizationType !== null && $this->bodyParameterName !== null; |
167
|
|
|
} |
168
|
|
|
|
169
|
85 |
|
public function getBodyDenormalizationType(): string |
170
|
|
|
{ |
171
|
85 |
|
if ($this->bodyDenormalizationType === null) { |
172
|
|
|
throw new RuntimeException( |
173
|
|
|
'No bodyDenormalizationType available, call hasBodyDenormalization beforehand' |
174
|
|
|
); |
175
|
|
|
} |
176
|
85 |
|
return $this->bodyDenormalizationType; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return string|null |
181
|
|
|
*/ |
182
|
26 |
|
public function getBodyDenormalizationGroup() |
183
|
|
|
{ |
184
|
26 |
|
return $this->bodyDenormalizationGroup; |
185
|
|
|
} |
186
|
|
|
|
187
|
17 |
|
public function getBodyParameterName(): string |
188
|
|
|
{ |
189
|
17 |
|
if ($this->bodyParameterName === null) { |
190
|
|
|
throw new RuntimeException( |
191
|
|
|
'No bodyParameterName available, call hasBodyDenormalization beforehand' |
192
|
|
|
); |
193
|
|
|
} |
194
|
17 |
|
return $this->bodyParameterName; |
195
|
|
|
} |
196
|
|
|
|
197
|
31 |
|
public function getSupportedRequestContentTypes(): array |
198
|
|
|
{ |
199
|
31 |
|
return $this->supportedContentTypes; |
200
|
|
|
} |
201
|
|
|
|
202
|
26 |
|
public function isJsonEncodedBody(): bool |
203
|
|
|
{ |
204
|
26 |
|
return $this->jsonEncodedBody; |
205
|
|
|
} |
206
|
|
|
|
207
|
5 |
|
public function isBodyOptional(): bool |
208
|
|
|
{ |
209
|
5 |
|
return $this->bodyOptional; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return string|null |
214
|
|
|
*/ |
215
|
94 |
|
public function getResponseNormalizationType() |
216
|
|
|
{ |
217
|
94 |
|
return $this->responseNormalizationType; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @return string|null |
222
|
|
|
*/ |
223
|
6 |
|
public function getResponseNormalizationGroup() |
224
|
|
|
{ |
225
|
6 |
|
return $this->responseNormalizationGroup; |
226
|
|
|
} |
227
|
|
|
|
228
|
81 |
|
public function getRequiredPermissions(): array |
229
|
|
|
{ |
230
|
81 |
|
return $this->requiredPermissions; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return array|PathAttributeResolverOptions[] |
235
|
|
|
*/ |
236
|
89 |
|
public function getPathAttributeResolverOptionsList(): array |
237
|
|
|
{ |
238
|
89 |
|
return $this->pathAttributeResolverOptionsList; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return array|QueryResolverOptions[] |
243
|
|
|
*/ |
244
|
91 |
|
public function getQueryResolverOptionsList(): array |
245
|
|
|
{ |
246
|
91 |
|
return $this->queryResolverOptionsList; |
247
|
|
|
} |
248
|
|
|
|
249
|
81 |
|
public function isBodyValidationNeeded(): bool |
250
|
|
|
{ |
251
|
81 |
|
return $this->bodyValidationOptions !== null && $this->bodyValidationOptions->isEnabled(); |
252
|
|
|
} |
253
|
|
|
|
254
|
81 |
|
public function disableBodyValidation(): self |
255
|
|
|
{ |
256
|
81 |
|
$this->bodyValidationOptions = null; |
257
|
81 |
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
81 |
|
public function getBodyValidationOptions(): ValidationOptions |
261
|
|
|
{ |
262
|
81 |
|
if ($this->bodyValidationOptions === null) { |
263
|
|
|
throw new RuntimeException('No bodyValidationOptions available, call isBodyValidationNeeded beforehand'); |
264
|
|
|
} |
265
|
81 |
|
return $this->bodyValidationOptions; |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|