|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Nyholm\Psr7; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
8
|
|
|
use Psr\Http\Message\StreamInterface; |
|
9
|
|
|
use Psr\Http\Message\UriInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Michael Dowling and contributors to guzzlehttp/psr7 |
|
13
|
|
|
* @author Tobias Nyholm <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class ServerRequest extends Request implements ServerRequestInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
private $attributes = []; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private $cookieParams = []; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var null|array|object |
|
29
|
|
|
*/ |
|
30
|
|
|
private $parsedBody; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
private $queryParams = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
|
|
private $serverParams; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
private $uploadedFiles = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $method HTTP method |
|
49
|
|
|
* @param string|UriInterface $uri URI |
|
50
|
|
|
* @param array $headers Request headers |
|
51
|
|
|
* @param string|null|resource|StreamInterface $body Request body |
|
52
|
|
|
* @param string $version Protocol version |
|
53
|
|
|
* @param array $serverParams Typically the $_SERVER superglobal |
|
54
|
|
|
*/ |
|
55
|
38 |
|
public function __construct( |
|
56
|
|
|
$method, |
|
57
|
|
|
$uri, |
|
58
|
|
|
array $headers = [], |
|
59
|
|
|
$body = null, |
|
60
|
|
|
$version = '1.1', |
|
61
|
|
|
array $serverParams = [] |
|
62
|
|
|
) { |
|
63
|
38 |
|
$this->serverParams = $serverParams; |
|
64
|
|
|
|
|
65
|
38 |
|
parent::__construct($method, $uri, $headers, $body, $version); |
|
66
|
38 |
|
} |
|
67
|
|
|
|
|
68
|
2 |
|
public function getServerParams() |
|
69
|
|
|
{ |
|
70
|
2 |
|
return $this->serverParams; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
9 |
|
public function getUploadedFiles() |
|
74
|
|
|
{ |
|
75
|
9 |
|
return $this->uploadedFiles; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
8 |
|
public function withUploadedFiles(array $uploadedFiles) |
|
79
|
|
|
{ |
|
80
|
8 |
|
$new = clone $this; |
|
81
|
8 |
|
$new->uploadedFiles = $uploadedFiles; |
|
82
|
|
|
|
|
83
|
8 |
|
return $new; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
3 |
|
public function getCookieParams() |
|
87
|
|
|
{ |
|
88
|
3 |
|
return $this->cookieParams; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
9 |
|
public function withCookieParams(array $cookies) |
|
92
|
|
|
{ |
|
93
|
9 |
|
$new = clone $this; |
|
94
|
9 |
|
$new->cookieParams = $cookies; |
|
95
|
|
|
|
|
96
|
9 |
|
return $new; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
3 |
|
public function getQueryParams() |
|
100
|
|
|
{ |
|
101
|
3 |
|
return $this->queryParams; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
9 |
|
public function withQueryParams(array $query) |
|
105
|
|
|
{ |
|
106
|
9 |
|
$new = clone $this; |
|
107
|
9 |
|
$new->queryParams = $query; |
|
108
|
|
|
|
|
109
|
9 |
|
return $new; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
3 |
|
public function getParsedBody() |
|
113
|
|
|
{ |
|
114
|
3 |
|
return $this->parsedBody; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
9 |
|
public function withParsedBody($data) |
|
118
|
|
|
{ |
|
119
|
9 |
|
$new = clone $this; |
|
120
|
9 |
|
$new->parsedBody = $data; |
|
121
|
|
|
|
|
122
|
9 |
|
return $new; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
2 |
|
public function getAttributes() |
|
126
|
|
|
{ |
|
127
|
2 |
|
return $this->attributes; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
2 |
|
public function getAttribute($attribute, $default = null) |
|
131
|
|
|
{ |
|
132
|
2 |
|
if (false === array_key_exists($attribute, $this->attributes)) { |
|
133
|
2 |
|
return $default; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
2 |
|
return $this->attributes[$attribute]; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
2 |
|
public function withAttribute($attribute, $value) |
|
140
|
|
|
{ |
|
141
|
2 |
|
$new = clone $this; |
|
142
|
2 |
|
$new->attributes[$attribute] = $value; |
|
143
|
|
|
|
|
144
|
2 |
|
return $new; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
2 |
|
public function withoutAttribute($attribute) |
|
148
|
|
|
{ |
|
149
|
2 |
|
if (false === array_key_exists($attribute, $this->attributes)) { |
|
150
|
1 |
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
2 |
|
$new = clone $this; |
|
154
|
2 |
|
unset($new->attributes[$attribute]); |
|
155
|
|
|
|
|
156
|
2 |
|
return $new; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|