|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace PTS\Psr7; |
|
5
|
|
|
|
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
8
|
|
|
use Psr\Http\Message\UploadedFileInterface; |
|
9
|
|
|
use Psr\Http\Message\UriInterface; |
|
10
|
|
|
use PTS\Psr7\Response\ServerMessageInterface; |
|
11
|
|
|
use function is_array; |
|
12
|
|
|
use function is_object; |
|
13
|
|
|
|
|
14
|
|
|
class ServerRequest extends Request implements ServerRequestInterface, ServerMessageInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use ServerMessage; |
|
17
|
|
|
|
|
18
|
|
|
protected array $cookieParams = []; |
|
19
|
|
|
|
|
20
|
|
|
/** @var array|object|null */ |
|
21
|
|
|
protected $parsedBody; |
|
22
|
|
|
protected array $queryParams = []; |
|
23
|
|
|
protected array $serverParams; |
|
24
|
|
|
|
|
25
|
|
|
/** @var UploadedFileInterface[] */ |
|
26
|
|
|
protected array $uploadedFiles = []; |
|
27
|
|
|
|
|
28
|
11 |
|
public function __construct( |
|
29
|
|
|
string $method, |
|
30
|
|
|
UriInterface $uri, |
|
31
|
|
|
array $headers = [], |
|
32
|
|
|
$body = null, |
|
33
|
|
|
string $version = '1.1', |
|
34
|
|
|
array $serverParams = [] |
|
35
|
|
|
) { |
|
36
|
11 |
|
parent::__construct($method, $uri, $headers, $body, $version); |
|
37
|
|
|
|
|
38
|
11 |
|
$this->serverParams = $serverParams; |
|
39
|
11 |
|
parse_str($uri->getQuery(), $this->queryParams); |
|
40
|
11 |
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function getServerParams(): array |
|
43
|
|
|
{ |
|
44
|
1 |
|
return $this->serverParams; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function getUploadedFiles(): array |
|
48
|
|
|
{ |
|
49
|
1 |
|
return $this->uploadedFiles; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
public function withUploadedFiles(array $uploadedFiles) |
|
53
|
|
|
{ |
|
54
|
2 |
|
$this->uploadedFiles = $uploadedFiles; |
|
55
|
2 |
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function getCookieParams(): array |
|
59
|
|
|
{ |
|
60
|
1 |
|
return $this->cookieParams; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
public function withCookieParams(array $cookies) |
|
64
|
|
|
{ |
|
65
|
2 |
|
$this->cookieParams = $cookies; |
|
66
|
2 |
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
public function getQueryParams(): array |
|
70
|
|
|
{ |
|
71
|
2 |
|
return $this->queryParams; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
2 |
|
public function withQueryParams(array $query) |
|
75
|
|
|
{ |
|
76
|
2 |
|
$this->queryParams = $query; |
|
77
|
2 |
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
public function getParsedBody() |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->parsedBody; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
3 |
|
public function withParsedBody($data) |
|
86
|
|
|
{ |
|
87
|
3 |
|
if (!is_array($data) && !is_object($data) && null !== $data) { |
|
88
|
1 |
|
throw new InvalidArgumentException('First parameter to withParsedBody MUST be object, array or null'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
2 |
|
$this->parsedBody = $data; |
|
92
|
2 |
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|