|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** |
4 | | - * High-performance PHP process supervisor and load balancer written in Go. Http core. |
| 4 | + * This file is part of RoadRunner package. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
5 | 8 | */ |
6 | 9 |
|
7 | 10 | declare(strict_types=1); |
8 | 11 |
|
9 | 12 | namespace Spiral\RoadRunner\Http; |
10 | 13 |
|
| 14 | +use JetBrains\PhpStorm\Immutable; |
| 15 | + |
| 16 | +/** |
| 17 | + * @psalm-immutable |
| 18 | + * |
| 19 | + * @psalm-type UploadedFile = array { |
| 20 | + * error: positive-int|0, |
| 21 | + * name: string, |
| 22 | + * tmpName: string, |
| 23 | + * size: positive-int|0, |
| 24 | + * mime: string |
| 25 | + * } |
| 26 | + * |
| 27 | + * @psalm-type HeadersList = array<string, array<array-key, string>> |
| 28 | + * @psalm-type AttributesList = array<string, mixed> |
| 29 | + * @psalm-type QueryArgumentsList = array<string, string> |
| 30 | + * @psalm-type CookiesList = array<string, string> |
| 31 | + * @psalm-type UploadedFilesList = array<array-key, UploadedFile> |
| 32 | + */ |
| 33 | +#[Immutable] |
11 | 34 | final class Request |
12 | 35 | { |
13 | | - public string $remoteAddr; |
14 | | - public string $protocol; |
15 | | - public string $method; |
16 | | - public string $uri; |
17 | | - public array $headers; |
18 | | - public array $cookies; |
19 | | - public array $uploads; |
20 | | - public array $attributes; |
21 | | - public array $query; |
22 | | - public ?string $body; |
23 | | - public bool $parsed; |
| 36 | + /** |
| 37 | + * @var string |
| 38 | + */ |
| 39 | + |
| 40 | + public string $remoteAddr = '127.0.0.1'; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var string |
| 44 | + */ |
| 45 | + public string $protocol = 'HTTP/1.0'; |
| 46 | + |
| 47 | + /** |
| 48 | + * @var string |
| 49 | + */ |
| 50 | + public string $method = 'GET'; |
| 51 | + |
| 52 | + /** |
| 53 | + * @var string |
| 54 | + */ |
| 55 | + public string $uri = 'http://localhost'; |
| 56 | + |
| 57 | + /** |
| 58 | + * @var HeadersList |
| 59 | + */ |
| 60 | + public array $headers = []; |
| 61 | + |
| 62 | + /** |
| 63 | + * @var CookiesList |
| 64 | + */ |
| 65 | + public array $cookies = []; |
| 66 | + |
| 67 | + /** |
| 68 | + * @var UploadedFilesList |
| 69 | + */ |
| 70 | + public array $uploads = []; |
| 71 | + |
| 72 | + /** |
| 73 | + * @var AttributesList |
| 74 | + */ |
| 75 | + public array $attributes = []; |
| 76 | + |
| 77 | + /** |
| 78 | + * @var QueryArgumentsList |
| 79 | + */ |
| 80 | + public array $query = []; |
| 81 | + |
| 82 | + /** |
| 83 | + * @var string |
| 84 | + */ |
| 85 | + public string $body = ''; |
| 86 | + |
| 87 | + /** |
| 88 | + * @var bool |
| 89 | + */ |
| 90 | + public bool $parsed = false; |
24 | 91 |
|
25 | 92 | /** |
26 | 93 | * @return string |
27 | 94 | */ |
28 | 95 | public function getRemoteAddr(): string |
29 | 96 | { |
30 | | - return $this->attributes['ipAddress'] ?? $this->remoteAddr ?? '127.0.0.1'; |
| 97 | + return (string)($this->attributes['ipAddress'] ?? $this->remoteAddr); |
31 | 98 | } |
32 | 99 |
|
33 | 100 | /** |
34 | 101 | * @return array|null |
| 102 | + * @throws \JsonException |
35 | 103 | */ |
36 | 104 | public function getParsedBody(): ?array |
37 | 105 | { |
38 | 106 | if ($this->parsed) { |
39 | | - return json_decode($this->body, true); |
| 107 | + return (array)\json_decode($this->body, true, 512, \JSON_THROW_ON_ERROR); |
40 | 108 | } |
41 | 109 |
|
42 | 110 | return null; |
|
0 commit comments