@@ -23,317 +23,317 @@ |
||
23 | 23 | |
24 | 24 | class ServerRequest extends Request implements ServerRequestInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * @var array<array-key, mixed> |
|
28 | - */ |
|
29 | - private array $serverParams; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var array<array-key, mixed> |
|
33 | - */ |
|
34 | - private array $queryParams; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array<array-key, mixed> |
|
38 | - */ |
|
39 | - private array $cookieParams; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array<array-key, mixed> |
|
43 | - */ |
|
44 | - private array $uploadedFiles = []; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array<array-key, mixed>|object|null |
|
48 | - */ |
|
49 | - private $parsedBody = null; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var array<array-key, mixed> |
|
53 | - */ |
|
54 | - private array $attributes; |
|
55 | - |
|
56 | - /** |
|
57 | - * Constructor of the class |
|
58 | - * |
|
59 | - * @param mixed $uri |
|
60 | - * @param array<string, string|string[]>|null $headers |
|
61 | - * |
|
62 | - * @param array<array-key, mixed> $serverParams |
|
63 | - * @param array<array-key, mixed> $queryParams |
|
64 | - * @param array<array-key, mixed> $cookieParams |
|
65 | - * @param array<array-key, mixed> $uploadedFiles |
|
66 | - * @param array<array-key, mixed>|object|null $parsedBody |
|
67 | - * @param array<array-key, mixed> $attributes |
|
68 | - * |
|
69 | - * @throws InvalidArgumentException |
|
70 | - */ |
|
71 | - public function __construct( |
|
72 | - ?string $protocolVersion = null, |
|
73 | - ?string $method = null, |
|
74 | - $uri = null, |
|
75 | - ?array $headers = null, |
|
76 | - ?StreamInterface $body = null, |
|
77 | - array $serverParams = [], |
|
78 | - array $queryParams = [], |
|
79 | - array $cookieParams = [], |
|
80 | - array $uploadedFiles = [], |
|
81 | - $parsedBody = null, |
|
82 | - array $attributes = [] |
|
83 | - ) { |
|
84 | - parent::__construct($method, $uri, $headers, $body); |
|
85 | - |
|
86 | - if ($protocolVersion !== null) { |
|
87 | - $this->setProtocolVersion($protocolVersion); |
|
88 | - } |
|
89 | - |
|
90 | - if ($uploadedFiles !== []) { |
|
91 | - $this->setUploadedFiles($uploadedFiles); |
|
92 | - } |
|
93 | - |
|
94 | - if ($parsedBody !== null) { |
|
95 | - $this->setParsedBody($parsedBody); |
|
96 | - } |
|
97 | - |
|
98 | - $this->serverParams = $serverParams; |
|
99 | - $this->queryParams = $queryParams; |
|
100 | - $this->cookieParams = $cookieParams; |
|
101 | - $this->attributes = $attributes; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * {@inheritDoc} |
|
106 | - * |
|
107 | - * @return array<array-key, mixed> |
|
108 | - */ |
|
109 | - public function getServerParams(): array |
|
110 | - { |
|
111 | - return $this->serverParams; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * {@inheritDoc} |
|
116 | - * |
|
117 | - * @return array<array-key, mixed> |
|
118 | - */ |
|
119 | - public function getQueryParams(): array |
|
120 | - { |
|
121 | - return $this->queryParams; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * {@inheritDoc} |
|
126 | - * |
|
127 | - * @param array<array-key, mixed> $query |
|
128 | - * |
|
129 | - * @return static |
|
130 | - */ |
|
131 | - public function withQueryParams(array $query): ServerRequestInterface |
|
132 | - { |
|
133 | - $clone = clone $this; |
|
134 | - $clone->queryParams = $query; |
|
135 | - |
|
136 | - return $clone; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * {@inheritDoc} |
|
141 | - * |
|
142 | - * @return array<array-key, mixed> |
|
143 | - */ |
|
144 | - public function getCookieParams(): array |
|
145 | - { |
|
146 | - return $this->cookieParams; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * {@inheritDoc} |
|
151 | - * |
|
152 | - * @param array<array-key, mixed> $cookies |
|
153 | - * |
|
154 | - * @return static |
|
155 | - */ |
|
156 | - public function withCookieParams(array $cookies): ServerRequestInterface |
|
157 | - { |
|
158 | - $clone = clone $this; |
|
159 | - $clone->cookieParams = $cookies; |
|
160 | - |
|
161 | - return $clone; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * {@inheritDoc} |
|
166 | - * |
|
167 | - * @return array<array-key, mixed> |
|
168 | - */ |
|
169 | - public function getUploadedFiles(): array |
|
170 | - { |
|
171 | - return $this->uploadedFiles; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * {@inheritDoc} |
|
176 | - * |
|
177 | - * @param array<array-key, mixed> $uploadedFiles |
|
178 | - * |
|
179 | - * @return static |
|
180 | - * |
|
181 | - * @throws InvalidArgumentException |
|
182 | - */ |
|
183 | - public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface |
|
184 | - { |
|
185 | - $clone = clone $this; |
|
186 | - $clone->setUploadedFiles($uploadedFiles); |
|
187 | - |
|
188 | - return $clone; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * {@inheritDoc} |
|
193 | - * |
|
194 | - * @return array<array-key, mixed>|object|null |
|
195 | - */ |
|
196 | - public function getParsedBody() |
|
197 | - { |
|
198 | - return $this->parsedBody; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * {@inheritDoc} |
|
203 | - * |
|
204 | - * @param array<array-key, mixed>|object|null $data |
|
205 | - * |
|
206 | - * @return static |
|
207 | - * |
|
208 | - * @throws InvalidArgumentException |
|
209 | - */ |
|
210 | - public function withParsedBody($data): ServerRequestInterface |
|
211 | - { |
|
212 | - $clone = clone $this; |
|
213 | - $clone->setParsedBody($data); |
|
214 | - |
|
215 | - return $clone; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * {@inheritDoc} |
|
220 | - * |
|
221 | - * @return array<array-key, mixed> |
|
222 | - */ |
|
223 | - public function getAttributes(): array |
|
224 | - { |
|
225 | - return $this->attributes; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * {@inheritDoc} |
|
230 | - * |
|
231 | - * @param array-key $name |
|
232 | - * @param mixed $default |
|
233 | - * |
|
234 | - * @return mixed |
|
235 | - */ |
|
236 | - public function getAttribute($name, $default = null) |
|
237 | - { |
|
238 | - if (!array_key_exists($name, $this->attributes)) { |
|
239 | - return $default; |
|
240 | - } |
|
241 | - |
|
242 | - return $this->attributes[$name]; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * {@inheritDoc} |
|
247 | - * |
|
248 | - * @param array-key $name |
|
249 | - * @param mixed $value |
|
250 | - * |
|
251 | - * @return static |
|
252 | - */ |
|
253 | - public function withAttribute($name, $value): ServerRequestInterface |
|
254 | - { |
|
255 | - $clone = clone $this; |
|
256 | - $clone->attributes[$name] = $value; |
|
257 | - |
|
258 | - return $clone; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * {@inheritDoc} |
|
263 | - * |
|
264 | - * @param array-key $name |
|
265 | - * |
|
266 | - * @return static |
|
267 | - */ |
|
268 | - public function withoutAttribute($name): ServerRequestInterface |
|
269 | - { |
|
270 | - $clone = clone $this; |
|
271 | - unset($clone->attributes[$name]); |
|
272 | - |
|
273 | - return $clone; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Sets the given uploaded files to the request |
|
278 | - * |
|
279 | - * @param array<array-key, mixed> $files |
|
280 | - * |
|
281 | - * @throws InvalidArgumentException |
|
282 | - */ |
|
283 | - final protected function setUploadedFiles(array $files): void |
|
284 | - { |
|
285 | - $this->validateUploadedFiles($files); |
|
286 | - |
|
287 | - $this->uploadedFiles = $files; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Sets the given parsed body to the request |
|
292 | - * |
|
293 | - * @param array<array-key, mixed>|object|null $data |
|
294 | - * |
|
295 | - * @throws InvalidArgumentException |
|
296 | - */ |
|
297 | - final protected function setParsedBody($data): void |
|
298 | - { |
|
299 | - $this->validateParsedBody($data); |
|
300 | - |
|
301 | - $this->parsedBody = $data; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Validates the given uploaded files |
|
306 | - * |
|
307 | - * @param array<array-key, mixed> $files |
|
308 | - * |
|
309 | - * @throws InvalidArgumentException |
|
310 | - */ |
|
311 | - private function validateUploadedFiles(array $files): void |
|
312 | - { |
|
313 | - if ($files === []) { |
|
314 | - return; |
|
315 | - } |
|
316 | - |
|
317 | - array_walk_recursive($files, /** @param mixed $file */ static function ($file): void { |
|
318 | - if (!($file instanceof UploadedFileInterface)) { |
|
319 | - throw new InvalidArgumentException('Invalid uploaded file'); |
|
320 | - } |
|
321 | - }); |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Validates the given parsed body |
|
326 | - * |
|
327 | - * @param mixed $data |
|
328 | - * |
|
329 | - * @throws InvalidArgumentException |
|
330 | - */ |
|
331 | - private function validateParsedBody($data): void |
|
332 | - { |
|
333 | - if ($data === null || is_array($data) || is_object($data)) { |
|
334 | - return; |
|
335 | - } |
|
336 | - |
|
337 | - throw new InvalidArgumentException('Invalid parsed body'); |
|
338 | - } |
|
26 | + /** |
|
27 | + * @var array<array-key, mixed> |
|
28 | + */ |
|
29 | + private array $serverParams; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var array<array-key, mixed> |
|
33 | + */ |
|
34 | + private array $queryParams; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array<array-key, mixed> |
|
38 | + */ |
|
39 | + private array $cookieParams; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array<array-key, mixed> |
|
43 | + */ |
|
44 | + private array $uploadedFiles = []; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array<array-key, mixed>|object|null |
|
48 | + */ |
|
49 | + private $parsedBody = null; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var array<array-key, mixed> |
|
53 | + */ |
|
54 | + private array $attributes; |
|
55 | + |
|
56 | + /** |
|
57 | + * Constructor of the class |
|
58 | + * |
|
59 | + * @param mixed $uri |
|
60 | + * @param array<string, string|string[]>|null $headers |
|
61 | + * |
|
62 | + * @param array<array-key, mixed> $serverParams |
|
63 | + * @param array<array-key, mixed> $queryParams |
|
64 | + * @param array<array-key, mixed> $cookieParams |
|
65 | + * @param array<array-key, mixed> $uploadedFiles |
|
66 | + * @param array<array-key, mixed>|object|null $parsedBody |
|
67 | + * @param array<array-key, mixed> $attributes |
|
68 | + * |
|
69 | + * @throws InvalidArgumentException |
|
70 | + */ |
|
71 | + public function __construct( |
|
72 | + ?string $protocolVersion = null, |
|
73 | + ?string $method = null, |
|
74 | + $uri = null, |
|
75 | + ?array $headers = null, |
|
76 | + ?StreamInterface $body = null, |
|
77 | + array $serverParams = [], |
|
78 | + array $queryParams = [], |
|
79 | + array $cookieParams = [], |
|
80 | + array $uploadedFiles = [], |
|
81 | + $parsedBody = null, |
|
82 | + array $attributes = [] |
|
83 | + ) { |
|
84 | + parent::__construct($method, $uri, $headers, $body); |
|
85 | + |
|
86 | + if ($protocolVersion !== null) { |
|
87 | + $this->setProtocolVersion($protocolVersion); |
|
88 | + } |
|
89 | + |
|
90 | + if ($uploadedFiles !== []) { |
|
91 | + $this->setUploadedFiles($uploadedFiles); |
|
92 | + } |
|
93 | + |
|
94 | + if ($parsedBody !== null) { |
|
95 | + $this->setParsedBody($parsedBody); |
|
96 | + } |
|
97 | + |
|
98 | + $this->serverParams = $serverParams; |
|
99 | + $this->queryParams = $queryParams; |
|
100 | + $this->cookieParams = $cookieParams; |
|
101 | + $this->attributes = $attributes; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * {@inheritDoc} |
|
106 | + * |
|
107 | + * @return array<array-key, mixed> |
|
108 | + */ |
|
109 | + public function getServerParams(): array |
|
110 | + { |
|
111 | + return $this->serverParams; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * {@inheritDoc} |
|
116 | + * |
|
117 | + * @return array<array-key, mixed> |
|
118 | + */ |
|
119 | + public function getQueryParams(): array |
|
120 | + { |
|
121 | + return $this->queryParams; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * {@inheritDoc} |
|
126 | + * |
|
127 | + * @param array<array-key, mixed> $query |
|
128 | + * |
|
129 | + * @return static |
|
130 | + */ |
|
131 | + public function withQueryParams(array $query): ServerRequestInterface |
|
132 | + { |
|
133 | + $clone = clone $this; |
|
134 | + $clone->queryParams = $query; |
|
135 | + |
|
136 | + return $clone; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * {@inheritDoc} |
|
141 | + * |
|
142 | + * @return array<array-key, mixed> |
|
143 | + */ |
|
144 | + public function getCookieParams(): array |
|
145 | + { |
|
146 | + return $this->cookieParams; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * {@inheritDoc} |
|
151 | + * |
|
152 | + * @param array<array-key, mixed> $cookies |
|
153 | + * |
|
154 | + * @return static |
|
155 | + */ |
|
156 | + public function withCookieParams(array $cookies): ServerRequestInterface |
|
157 | + { |
|
158 | + $clone = clone $this; |
|
159 | + $clone->cookieParams = $cookies; |
|
160 | + |
|
161 | + return $clone; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * {@inheritDoc} |
|
166 | + * |
|
167 | + * @return array<array-key, mixed> |
|
168 | + */ |
|
169 | + public function getUploadedFiles(): array |
|
170 | + { |
|
171 | + return $this->uploadedFiles; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * {@inheritDoc} |
|
176 | + * |
|
177 | + * @param array<array-key, mixed> $uploadedFiles |
|
178 | + * |
|
179 | + * @return static |
|
180 | + * |
|
181 | + * @throws InvalidArgumentException |
|
182 | + */ |
|
183 | + public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface |
|
184 | + { |
|
185 | + $clone = clone $this; |
|
186 | + $clone->setUploadedFiles($uploadedFiles); |
|
187 | + |
|
188 | + return $clone; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * {@inheritDoc} |
|
193 | + * |
|
194 | + * @return array<array-key, mixed>|object|null |
|
195 | + */ |
|
196 | + public function getParsedBody() |
|
197 | + { |
|
198 | + return $this->parsedBody; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * {@inheritDoc} |
|
203 | + * |
|
204 | + * @param array<array-key, mixed>|object|null $data |
|
205 | + * |
|
206 | + * @return static |
|
207 | + * |
|
208 | + * @throws InvalidArgumentException |
|
209 | + */ |
|
210 | + public function withParsedBody($data): ServerRequestInterface |
|
211 | + { |
|
212 | + $clone = clone $this; |
|
213 | + $clone->setParsedBody($data); |
|
214 | + |
|
215 | + return $clone; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * {@inheritDoc} |
|
220 | + * |
|
221 | + * @return array<array-key, mixed> |
|
222 | + */ |
|
223 | + public function getAttributes(): array |
|
224 | + { |
|
225 | + return $this->attributes; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * {@inheritDoc} |
|
230 | + * |
|
231 | + * @param array-key $name |
|
232 | + * @param mixed $default |
|
233 | + * |
|
234 | + * @return mixed |
|
235 | + */ |
|
236 | + public function getAttribute($name, $default = null) |
|
237 | + { |
|
238 | + if (!array_key_exists($name, $this->attributes)) { |
|
239 | + return $default; |
|
240 | + } |
|
241 | + |
|
242 | + return $this->attributes[$name]; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * {@inheritDoc} |
|
247 | + * |
|
248 | + * @param array-key $name |
|
249 | + * @param mixed $value |
|
250 | + * |
|
251 | + * @return static |
|
252 | + */ |
|
253 | + public function withAttribute($name, $value): ServerRequestInterface |
|
254 | + { |
|
255 | + $clone = clone $this; |
|
256 | + $clone->attributes[$name] = $value; |
|
257 | + |
|
258 | + return $clone; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * {@inheritDoc} |
|
263 | + * |
|
264 | + * @param array-key $name |
|
265 | + * |
|
266 | + * @return static |
|
267 | + */ |
|
268 | + public function withoutAttribute($name): ServerRequestInterface |
|
269 | + { |
|
270 | + $clone = clone $this; |
|
271 | + unset($clone->attributes[$name]); |
|
272 | + |
|
273 | + return $clone; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Sets the given uploaded files to the request |
|
278 | + * |
|
279 | + * @param array<array-key, mixed> $files |
|
280 | + * |
|
281 | + * @throws InvalidArgumentException |
|
282 | + */ |
|
283 | + final protected function setUploadedFiles(array $files): void |
|
284 | + { |
|
285 | + $this->validateUploadedFiles($files); |
|
286 | + |
|
287 | + $this->uploadedFiles = $files; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Sets the given parsed body to the request |
|
292 | + * |
|
293 | + * @param array<array-key, mixed>|object|null $data |
|
294 | + * |
|
295 | + * @throws InvalidArgumentException |
|
296 | + */ |
|
297 | + final protected function setParsedBody($data): void |
|
298 | + { |
|
299 | + $this->validateParsedBody($data); |
|
300 | + |
|
301 | + $this->parsedBody = $data; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Validates the given uploaded files |
|
306 | + * |
|
307 | + * @param array<array-key, mixed> $files |
|
308 | + * |
|
309 | + * @throws InvalidArgumentException |
|
310 | + */ |
|
311 | + private function validateUploadedFiles(array $files): void |
|
312 | + { |
|
313 | + if ($files === []) { |
|
314 | + return; |
|
315 | + } |
|
316 | + |
|
317 | + array_walk_recursive($files, /** @param mixed $file */ static function ($file): void { |
|
318 | + if (!($file instanceof UploadedFileInterface)) { |
|
319 | + throw new InvalidArgumentException('Invalid uploaded file'); |
|
320 | + } |
|
321 | + }); |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Validates the given parsed body |
|
326 | + * |
|
327 | + * @param mixed $data |
|
328 | + * |
|
329 | + * @throws InvalidArgumentException |
|
330 | + */ |
|
331 | + private function validateParsedBody($data): void |
|
332 | + { |
|
333 | + if ($data === null || is_array($data) || is_object($data)) { |
|
334 | + return; |
|
335 | + } |
|
336 | + |
|
337 | + throw new InvalidArgumentException('Invalid parsed body'); |
|
338 | + } |
|
339 | 339 | } |
@@ -314,7 +314,7 @@ |
||
314 | 314 | return; |
315 | 315 | } |
316 | 316 | |
317 | - array_walk_recursive($files, /** @param mixed $file */ static function ($file): void { |
|
317 | + array_walk_recursive($files, /** @param mixed $file */ static function($file): void { |
|
318 | 318 | if (!($file instanceof UploadedFileInterface)) { |
319 | 319 | throw new InvalidArgumentException('Invalid uploaded file'); |
320 | 320 | } |