-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerRequest.php
More file actions
207 lines (175 loc) · 3.88 KB
/
ServerRequest.php
File metadata and controls
207 lines (175 loc) · 3.88 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
namespace HackPHP\Http\Request;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\ServerRequestInterface;
class ServerRequest extends Request implements ServerRequestInterface
{
/**
* Data related to the incoming request environment.
*
* @var array
*/
protected array $serverParams;
/**
* Cookies sent by the client to the server.
*
* @var array
*/
protected array $cookieParams = [];
/**
* Deserialized query string arguments.
* Get it from getUri()->getQuery() or from the QUERY_STRING server param.
*
* @var array
*/
protected array $queryParams = [];
/**
* Uploaded Files.
*
* @var UploadedFileInterface[]
*/
protected array $uploadedFiles = [];
/**
* @var null|array|object
*/
protected $parsedBody;
/**
* Request attributes.
*
* @var array
*/
protected array $attributes = [];
/**
* Create new ServerRequest.
*
* @param string $method
* @param UriInterface|string|null $uri
* @param array $headers
* @param StreamInterface|resource|string|null $body
* @param array $serverParam
*/
public function __construct(
string $method = 'GET',
$uri = null,
array $headers = [],
$body = null,
array $serverParams = []
) {
parent::__construct($method, $uri, $headers, $body);
$this->serverParams = $serverParams;
}
/**
* @inheritDoc
*/
public function getServerParams()
{
return $this->serverParams;
}
/**
* @inheritDoc
*/
public function getCookieParams()
{
return $this->cookieParams;
}
/**
* @inheritDoc
*/
public function withCookieParams(array $cookies)
{
$clone = clone $this;
$clone->cookieParams = $cookies;
return $clone;
}
/**
* @inheritDoc
*/
public function getQueryParams()
{
return $this->queryParams;
}
/**
* @inheritDoc
*/
public function withQueryParams(array $query)
{
$clone = clone $this;
$clone->queryParams = $query;
return $clone;
}
/**
* @inheritDoc
*/
public function getUploadedFiles()
{
return $this->uploadedFiles;
}
/**
* @inheritDoc
*/
public function withUploadedFiles(array $uploadedFiles)
{
$clone = clone $this;
$clone->uploadedFiles = $uploadedFiles;
return $clone;
}
/**
* @inheritDoc
*/
public function getParsedBody()
{
return $this->parsedBody;
}
/**
* @inheritDoc
*/
public function withParsedBody($data)
{
if (!is_array($data) && !is_object($data) && !is_null($data)) {
throw new \InvalidArgumentException(
'First parameter to withParsedBody MUST be object, array or null'
);
}
$clone = clone $this;
$clone->parsedBody = $data;
return $clone;
}
/**
* @inheritDoc
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @inheritDoc
*/
public function getAttribute($name, $default = null)
{
if (!array_key_exists($name, $this->attributes)) {
return $default;
}
return $this->attributes[$name];
}
/**
* @inheritDoc
*/
public function withAttribute($name, $value)
{
$clone = clone $this;
$clone->attributes[$name] = $value;
return $clone;
}
/**
* @inheritDoc
*/
public function withoutAttribute($name)
{
if (!array_key_exists($name, $this->attributes)) {
return $this;
}
$clone = clone $this;
unset($clone->attributes[$name]);
return $clone;
}
}