1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/boot project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Boot\Middleware\Action; |
10
|
|
|
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
12
|
|
|
use Psr\Http\Message\StreamInterface; |
13
|
|
|
use Psr\Http\Message\UriInterface; |
14
|
|
|
|
15
|
|
|
class DaikonRequest implements ServerRequestInterface |
16
|
|
|
{ |
17
|
|
|
public const ERRORS = '_errors'; |
18
|
|
|
public const PAYLOAD = '_payload'; |
19
|
|
|
public const STATUS_CODE = '_status_code'; |
20
|
|
|
public const RESPONDER = '_responder'; |
21
|
|
|
|
22
|
|
|
protected ServerRequestInterface $serverRequest; |
23
|
|
|
|
24
|
|
|
private function __construct(ServerRequestInterface $serverRequest) |
25
|
|
|
{ |
26
|
|
|
$this->serverRequest = $serverRequest; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** @return static */ |
30
|
|
|
public static function wrap(ServerRequestInterface $serverRequest): self |
31
|
|
|
{ |
32
|
|
|
return new self($serverRequest); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function unwrap(): ServerRequestInterface |
36
|
|
|
{ |
37
|
|
|
return $this->serverRequest; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param mixed $errors |
42
|
|
|
* @return static |
43
|
|
|
*/ |
44
|
|
|
public function withErrors($errors): self |
45
|
|
|
{ |
46
|
|
|
return static::wrap($this->serverRequest->withAttribute(self::ERRORS, $errors)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param mixed $default |
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
|
|
public function getErrors($default = null) |
54
|
|
|
{ |
55
|
|
|
return $this->serverRequest->getAttribute(self::ERRORS, $default); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param mixed $payload |
60
|
|
|
* @return static |
61
|
|
|
*/ |
62
|
|
|
public function withPayload($payload): self |
63
|
|
|
{ |
64
|
|
|
return static::wrap($this->serverRequest->withAttribute(self::PAYLOAD, $payload)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param mixed $default |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function getPayload($default = null) |
72
|
|
|
{ |
73
|
|
|
return $this->serverRequest->getAttribute(self::PAYLOAD, $default); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param mixed $responder |
78
|
|
|
* @return static |
79
|
|
|
*/ |
80
|
|
|
public function withResponder($responder): self |
81
|
|
|
{ |
82
|
|
|
return static::wrap($this->serverRequest->withAttribute(self::RESPONDER, $responder)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param mixed $default |
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
|
|
public function getResponder($default = null) |
90
|
|
|
{ |
91
|
|
|
return $this->serverRequest->getAttribute(self::RESPONDER, $default); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param mixed $statusCode |
96
|
|
|
* @return static |
97
|
|
|
*/ |
98
|
|
|
public function withStatusCode($statusCode): self |
99
|
|
|
{ |
100
|
|
|
return static::wrap($this->serverRequest->withAttribute(self::STATUS_CODE, $statusCode)); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param mixed $default |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function getStatusCode($default = null) |
108
|
|
|
{ |
109
|
|
|
return $this->getAttribute(self::STATUS_CODE, $default); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getServerParams() |
113
|
|
|
{ |
114
|
|
|
return $this->serverRequest->getServerParams(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getCookieParams() |
118
|
|
|
{ |
119
|
|
|
return $this->serverRequest->getCookieParams(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function withCookieParams(array $cookies) |
123
|
|
|
{ |
124
|
|
|
return static::wrap($this->serverRequest->withCookieParams($cookies)); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function getQueryParams() |
128
|
|
|
{ |
129
|
|
|
return $this->serverRequest->getQueryParams(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function withQueryParams(array $query) |
133
|
|
|
{ |
134
|
|
|
return static::wrap($this->serverRequest->withQueryParams($query)); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getUploadedFiles() |
138
|
|
|
{ |
139
|
|
|
return $this->serverRequest->getUploadedFiles(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function withUploadedFiles(array $uploadedFiles) |
143
|
|
|
{ |
144
|
|
|
return static::wrap($this->serverRequest->withUploadedFiles($uploadedFiles)); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getParsedBody() |
148
|
|
|
{ |
149
|
|
|
return $this->serverRequest->getParsedBody(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function withParsedBody($data) |
153
|
|
|
{ |
154
|
|
|
return static::wrap($this->serverRequest->withParsedBody($data)); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getAttributes() |
158
|
|
|
{ |
159
|
|
|
return $this->serverRequest->getAttributes(); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function getAttribute($name, $default = null) |
163
|
|
|
{ |
164
|
|
|
return $this->serverRequest->getAttribute($name, $default); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function withAttribute($name, $value) |
168
|
|
|
{ |
169
|
|
|
return static::wrap($this->serverRequest->withAttribute($name, $value)); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function withoutAttribute($name) |
173
|
|
|
{ |
174
|
|
|
return static::wrap($this->serverRequest->withoutAttribute($name)); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function getRequestTarget() |
178
|
|
|
{ |
179
|
|
|
return $this->serverRequest->getRequestTarget(); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function withRequestTarget($requestTarget) |
183
|
|
|
{ |
184
|
|
|
return static::wrap($this->serverRequest->withRequestTarget($requestTarget)); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function getMethod() |
188
|
|
|
{ |
189
|
|
|
return $this->serverRequest->getMethod(); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function withMethod($method) |
193
|
|
|
{ |
194
|
|
|
return static::wrap($this->serverRequest->withMethod($method)); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function getUri() |
198
|
|
|
{ |
199
|
|
|
return $this->serverRequest->getUri(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function withUri(UriInterface $uri, $preserveHost = false) |
203
|
|
|
{ |
204
|
|
|
return static::wrap($this->serverRequest->withUri($uri, $preserveHost)); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function getProtocolVersion() |
208
|
|
|
{ |
209
|
|
|
return $this->serverRequest->getProtocolVersion(); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function withProtocolVersion($version) |
213
|
|
|
{ |
214
|
|
|
return static::wrap($this->serverRequest->withProtocolVersion($version)); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function getHeaders() |
218
|
|
|
{ |
219
|
|
|
return $this->serverRequest->getHeaders(); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function hasHeader($name) |
223
|
|
|
{ |
224
|
|
|
return $this->serverRequest->hasHeader($name); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function getHeader($name) |
228
|
|
|
{ |
229
|
|
|
return $this->serverRequest->getHeader($name); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function getHeaderLine($name) |
233
|
|
|
{ |
234
|
|
|
return $this->serverRequest->getHeaderLine($name); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function withHeader($name, $value) |
238
|
|
|
{ |
239
|
|
|
return static::wrap($this->serverRequest->withHeader($name, $value)); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function withAddedHeader($name, $value) |
243
|
|
|
{ |
244
|
|
|
return static::wrap($this->serverRequest->withAddedHeader($name, $value)); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function withoutHeader($name) |
248
|
|
|
{ |
249
|
|
|
return static::wrap($this->serverRequest->withoutHeader($name)); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
public function getBody() |
253
|
|
|
{ |
254
|
|
|
return $this->serverRequest->getBody(); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
public function withBody(StreamInterface $body) |
258
|
|
|
{ |
259
|
|
|
return static::wrap($this->serverRequest->withBody($body)); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|