@@ -27,13 +27,13 @@ |
||
27 | 27 | final class PhpMemoryStream extends Stream |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Constructor of the class |
|
32 | - * |
|
33 | - * @param string $mode |
|
34 | - */ |
|
35 | - public function __construct(string $mode = 'r+b') |
|
36 | - { |
|
37 | - parent::__construct(fopen('php://memory', $mode)); |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor of the class |
|
32 | + * |
|
33 | + * @param string $mode |
|
34 | + */ |
|
35 | + public function __construct(string $mode = 'r+b') |
|
36 | + { |
|
37 | + parent::__construct(fopen('php://memory', $mode)); |
|
38 | + } |
|
39 | 39 | } |
@@ -28,18 +28,18 @@ |
||
28 | 28 | final class PhpInputStream extends Stream |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Constructor of the class |
|
33 | - */ |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - $input = fopen('php://input', 'rb'); |
|
37 | - $resource = fopen('php://temp', 'r+b'); |
|
31 | + /** |
|
32 | + * Constructor of the class |
|
33 | + */ |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + $input = fopen('php://input', 'rb'); |
|
37 | + $resource = fopen('php://temp', 'r+b'); |
|
38 | 38 | |
39 | - stream_copy_to_stream($input, $resource); |
|
39 | + stream_copy_to_stream($input, $resource); |
|
40 | 40 | |
41 | - parent::__construct($resource); |
|
41 | + parent::__construct($resource); |
|
42 | 42 | |
43 | - $this->rewind(); |
|
44 | - } |
|
43 | + $this->rewind(); |
|
44 | + } |
|
45 | 45 | } |
@@ -31,30 +31,30 @@ |
||
31 | 31 | final class FileStream extends Stream |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Constructor of the class |
|
36 | - * |
|
37 | - * @param string $filename |
|
38 | - * @param string $mode |
|
39 | - * |
|
40 | - * @throws RuntimeException |
|
41 | - */ |
|
42 | - public function __construct(string $filename, string $mode) |
|
43 | - { |
|
44 | - try { |
|
45 | - $resource = fopen($filename, $mode); |
|
46 | - } catch (Throwable $e) { |
|
47 | - $resource = false; |
|
48 | - } |
|
49 | - |
|
50 | - if (!is_resource($resource)) { |
|
51 | - throw new RuntimeException(sprintf( |
|
52 | - 'Unable to open the file "%s" in the mode "%s"', |
|
53 | - $filename, |
|
54 | - $mode |
|
55 | - )); |
|
56 | - } |
|
57 | - |
|
58 | - parent::__construct($resource); |
|
59 | - } |
|
34 | + /** |
|
35 | + * Constructor of the class |
|
36 | + * |
|
37 | + * @param string $filename |
|
38 | + * @param string $mode |
|
39 | + * |
|
40 | + * @throws RuntimeException |
|
41 | + */ |
|
42 | + public function __construct(string $filename, string $mode) |
|
43 | + { |
|
44 | + try { |
|
45 | + $resource = fopen($filename, $mode); |
|
46 | + } catch (Throwable $e) { |
|
47 | + $resource = false; |
|
48 | + } |
|
49 | + |
|
50 | + if (!is_resource($resource)) { |
|
51 | + throw new RuntimeException(sprintf( |
|
52 | + 'Unable to open the file "%s" in the mode "%s"', |
|
53 | + $filename, |
|
54 | + $mode |
|
55 | + )); |
|
56 | + } |
|
57 | + |
|
58 | + parent::__construct($resource); |
|
59 | + } |
|
60 | 60 | } |
@@ -35,23 +35,23 @@ |
||
35 | 35 | final class TmpfileStream extends Stream |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * Constructor of the class |
|
40 | - * |
|
41 | - * @throws RuntimeException |
|
42 | - */ |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - $dirname = sys_get_temp_dir(); |
|
46 | - if (!is_writable($dirname)) { |
|
47 | - throw new RuntimeException('Temporary files directory is not writable'); |
|
48 | - } |
|
49 | - |
|
50 | - $resource = tmpfile(); |
|
51 | - if (!is_resource($resource)) { |
|
52 | - throw new RuntimeException('Temporary file cannot be created or opened'); |
|
53 | - } |
|
54 | - |
|
55 | - parent::__construct($resource); |
|
56 | - } |
|
38 | + /** |
|
39 | + * Constructor of the class |
|
40 | + * |
|
41 | + * @throws RuntimeException |
|
42 | + */ |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + $dirname = sys_get_temp_dir(); |
|
46 | + if (!is_writable($dirname)) { |
|
47 | + throw new RuntimeException('Temporary files directory is not writable'); |
|
48 | + } |
|
49 | + |
|
50 | + $resource = tmpfile(); |
|
51 | + if (!is_resource($resource)) { |
|
52 | + throw new RuntimeException('Temporary file cannot be created or opened'); |
|
53 | + } |
|
54 | + |
|
55 | + parent::__construct($resource); |
|
56 | + } |
|
57 | 57 | } |
@@ -26,59 +26,59 @@ |
||
26 | 26 | class ServerRequestFactory implements ServerRequestFactoryInterface |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Creates a new request from superglobals variables |
|
31 | - * |
|
32 | - * @param array|null $serverParams |
|
33 | - * @param array|null $queryParams |
|
34 | - * @param array|null $cookieParams |
|
35 | - * @param array|null $uploadedFiles |
|
36 | - * @param array|null $parsedBody |
|
37 | - * |
|
38 | - * @return ServerRequestInterface |
|
39 | - * |
|
40 | - * @link http://php.net/manual/en/language.variables.superglobals.php |
|
41 | - * @link https://www.php-fig.org/psr/psr-15/meta/ |
|
42 | - */ |
|
43 | - public static function fromGlobals( |
|
44 | - ?array $serverParams = null, |
|
45 | - ?array $queryParams = null, |
|
46 | - ?array $cookieParams = null, |
|
47 | - ?array $uploadedFiles = null, |
|
48 | - ?array $parsedBody = null |
|
49 | - ): ServerRequestInterface { |
|
50 | - $serverParams ??= $_SERVER; |
|
51 | - $queryParams ??= $_GET; |
|
52 | - $cookieParams ??= $_COOKIE; |
|
53 | - $uploadedFiles ??= $_FILES; |
|
54 | - $parsedBody ??= $_POST; |
|
29 | + /** |
|
30 | + * Creates a new request from superglobals variables |
|
31 | + * |
|
32 | + * @param array|null $serverParams |
|
33 | + * @param array|null $queryParams |
|
34 | + * @param array|null $cookieParams |
|
35 | + * @param array|null $uploadedFiles |
|
36 | + * @param array|null $parsedBody |
|
37 | + * |
|
38 | + * @return ServerRequestInterface |
|
39 | + * |
|
40 | + * @link http://php.net/manual/en/language.variables.superglobals.php |
|
41 | + * @link https://www.php-fig.org/psr/psr-15/meta/ |
|
42 | + */ |
|
43 | + public static function fromGlobals( |
|
44 | + ?array $serverParams = null, |
|
45 | + ?array $queryParams = null, |
|
46 | + ?array $cookieParams = null, |
|
47 | + ?array $uploadedFiles = null, |
|
48 | + ?array $parsedBody = null |
|
49 | + ): ServerRequestInterface { |
|
50 | + $serverParams ??= $_SERVER; |
|
51 | + $queryParams ??= $_GET; |
|
52 | + $cookieParams ??= $_COOKIE; |
|
53 | + $uploadedFiles ??= $_FILES; |
|
54 | + $parsedBody ??= $_POST; |
|
55 | 55 | |
56 | - return new ServerRequest( |
|
57 | - server_request_protocol_version($serverParams), |
|
58 | - server_request_method($serverParams), |
|
59 | - server_request_uri($serverParams), |
|
60 | - server_request_headers($serverParams), |
|
61 | - new PhpInputStream(), |
|
62 | - $serverParams, |
|
63 | - $queryParams, |
|
64 | - $cookieParams, |
|
65 | - server_request_files($uploadedFiles), |
|
66 | - $parsedBody |
|
67 | - ); |
|
68 | - } |
|
56 | + return new ServerRequest( |
|
57 | + server_request_protocol_version($serverParams), |
|
58 | + server_request_method($serverParams), |
|
59 | + server_request_uri($serverParams), |
|
60 | + server_request_headers($serverParams), |
|
61 | + new PhpInputStream(), |
|
62 | + $serverParams, |
|
63 | + $queryParams, |
|
64 | + $cookieParams, |
|
65 | + server_request_files($uploadedFiles), |
|
66 | + $parsedBody |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritdoc} |
|
72 | - */ |
|
73 | - public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface |
|
74 | - { |
|
75 | - return new ServerRequest( |
|
76 | - server_request_protocol_version($serverParams), |
|
77 | - $method, |
|
78 | - $uri, |
|
79 | - server_request_headers($serverParams), |
|
80 | - null, // body |
|
81 | - $serverParams |
|
82 | - ); |
|
83 | - } |
|
70 | + /** |
|
71 | + * {@inheritdoc} |
|
72 | + */ |
|
73 | + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface |
|
74 | + { |
|
75 | + return new ServerRequest( |
|
76 | + server_request_protocol_version($serverParams), |
|
77 | + $method, |
|
78 | + $uri, |
|
79 | + server_request_headers($serverParams), |
|
80 | + null, // body |
|
81 | + $serverParams |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -35,241 +35,241 @@ |
||
35 | 35 | class Response extends Message implements ResponseInterface, StatusCodeInterface |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * List of Reason Phrases |
|
40 | - * |
|
41 | - * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
42 | - * |
|
43 | - * @var array<int<100, 599>, non-empty-string> |
|
44 | - */ |
|
45 | - public const REASON_PHRASES = [ |
|
38 | + /** |
|
39 | + * List of Reason Phrases |
|
40 | + * |
|
41 | + * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
42 | + * |
|
43 | + * @var array<int<100, 599>, non-empty-string> |
|
44 | + */ |
|
45 | + public const REASON_PHRASES = [ |
|
46 | 46 | |
47 | - // 1xx |
|
48 | - 100 => 'Continue', |
|
49 | - 101 => 'Switching Protocols', |
|
50 | - 102 => 'Processing', |
|
51 | - 103 => 'Early Hints', |
|
47 | + // 1xx |
|
48 | + 100 => 'Continue', |
|
49 | + 101 => 'Switching Protocols', |
|
50 | + 102 => 'Processing', |
|
51 | + 103 => 'Early Hints', |
|
52 | 52 | |
53 | - // 2xx |
|
54 | - 200 => 'OK', |
|
55 | - 201 => 'Created', |
|
56 | - 202 => 'Accepted', |
|
57 | - 203 => 'Non-Authoritative Information', |
|
58 | - 204 => 'No Content', |
|
59 | - 205 => 'Reset Content', |
|
60 | - 206 => 'Partial Content', |
|
61 | - 207 => 'Multi-Status', |
|
62 | - 208 => 'Already Reported', |
|
63 | - 226 => 'IM Used', |
|
53 | + // 2xx |
|
54 | + 200 => 'OK', |
|
55 | + 201 => 'Created', |
|
56 | + 202 => 'Accepted', |
|
57 | + 203 => 'Non-Authoritative Information', |
|
58 | + 204 => 'No Content', |
|
59 | + 205 => 'Reset Content', |
|
60 | + 206 => 'Partial Content', |
|
61 | + 207 => 'Multi-Status', |
|
62 | + 208 => 'Already Reported', |
|
63 | + 226 => 'IM Used', |
|
64 | 64 | |
65 | - // 3xx |
|
66 | - 300 => 'Multiple Choices', |
|
67 | - 301 => 'Moved Permanently', |
|
68 | - 302 => 'Found', |
|
69 | - 303 => 'See Other', |
|
70 | - 304 => 'Not Modified', |
|
71 | - 305 => 'Use Proxy', |
|
72 | - 307 => 'Temporary Redirect', |
|
73 | - 308 => 'Permanent Redirect', |
|
65 | + // 3xx |
|
66 | + 300 => 'Multiple Choices', |
|
67 | + 301 => 'Moved Permanently', |
|
68 | + 302 => 'Found', |
|
69 | + 303 => 'See Other', |
|
70 | + 304 => 'Not Modified', |
|
71 | + 305 => 'Use Proxy', |
|
72 | + 307 => 'Temporary Redirect', |
|
73 | + 308 => 'Permanent Redirect', |
|
74 | 74 | |
75 | - // 4xx |
|
76 | - 400 => 'Bad Request', |
|
77 | - 401 => 'Unauthorized', |
|
78 | - 402 => 'Payment Required', |
|
79 | - 403 => 'Forbidden', |
|
80 | - 404 => 'Not Found', |
|
81 | - 405 => 'Method Not Allowed', |
|
82 | - 406 => 'Not Acceptable', |
|
83 | - 407 => 'Proxy Authentication Required', |
|
84 | - 408 => 'Request Timeout', |
|
85 | - 409 => 'Conflict', |
|
86 | - 410 => 'Gone', |
|
87 | - 411 => 'Length Required', |
|
88 | - 412 => 'Precondition Failed', |
|
89 | - 413 => 'Payload Too Large', |
|
90 | - 414 => 'URI Too Long', |
|
91 | - 415 => 'Unsupported Media Type', |
|
92 | - 416 => 'Range Not Satisfiable', |
|
93 | - 417 => 'Expectation Failed', |
|
94 | - 421 => 'Misdirected Request', |
|
95 | - 422 => 'Unprocessable Entity', |
|
96 | - 423 => 'Locked', |
|
97 | - 424 => 'Failed Dependency', |
|
98 | - 425 => 'Too Early', |
|
99 | - 426 => 'Upgrade Required', |
|
100 | - 428 => 'Precondition Required', |
|
101 | - 429 => 'Too Many Requests', |
|
102 | - 431 => 'Request Header Fields Too Large', |
|
103 | - 451 => 'Unavailable For Legal Reasons', |
|
75 | + // 4xx |
|
76 | + 400 => 'Bad Request', |
|
77 | + 401 => 'Unauthorized', |
|
78 | + 402 => 'Payment Required', |
|
79 | + 403 => 'Forbidden', |
|
80 | + 404 => 'Not Found', |
|
81 | + 405 => 'Method Not Allowed', |
|
82 | + 406 => 'Not Acceptable', |
|
83 | + 407 => 'Proxy Authentication Required', |
|
84 | + 408 => 'Request Timeout', |
|
85 | + 409 => 'Conflict', |
|
86 | + 410 => 'Gone', |
|
87 | + 411 => 'Length Required', |
|
88 | + 412 => 'Precondition Failed', |
|
89 | + 413 => 'Payload Too Large', |
|
90 | + 414 => 'URI Too Long', |
|
91 | + 415 => 'Unsupported Media Type', |
|
92 | + 416 => 'Range Not Satisfiable', |
|
93 | + 417 => 'Expectation Failed', |
|
94 | + 421 => 'Misdirected Request', |
|
95 | + 422 => 'Unprocessable Entity', |
|
96 | + 423 => 'Locked', |
|
97 | + 424 => 'Failed Dependency', |
|
98 | + 425 => 'Too Early', |
|
99 | + 426 => 'Upgrade Required', |
|
100 | + 428 => 'Precondition Required', |
|
101 | + 429 => 'Too Many Requests', |
|
102 | + 431 => 'Request Header Fields Too Large', |
|
103 | + 451 => 'Unavailable For Legal Reasons', |
|
104 | 104 | |
105 | - // 5xx |
|
106 | - 500 => 'Internal Server Error', |
|
107 | - 501 => 'Not Implemented', |
|
108 | - 502 => 'Bad Gateway', |
|
109 | - 503 => 'Service Unavailable', |
|
110 | - 504 => 'Gateway Timeout', |
|
111 | - 505 => 'HTTP Version Not Supported', |
|
112 | - 506 => 'Variant Also Negotiates', |
|
113 | - 507 => 'Insufficient Storage', |
|
114 | - 508 => 'Loop Detected', |
|
115 | - 510 => 'Not Extended', |
|
116 | - 511 => 'Network Authentication Required', |
|
117 | - ]; |
|
105 | + // 5xx |
|
106 | + 500 => 'Internal Server Error', |
|
107 | + 501 => 'Not Implemented', |
|
108 | + 502 => 'Bad Gateway', |
|
109 | + 503 => 'Service Unavailable', |
|
110 | + 504 => 'Gateway Timeout', |
|
111 | + 505 => 'HTTP Version Not Supported', |
|
112 | + 506 => 'Variant Also Negotiates', |
|
113 | + 507 => 'Insufficient Storage', |
|
114 | + 508 => 'Loop Detected', |
|
115 | + 510 => 'Not Extended', |
|
116 | + 511 => 'Network Authentication Required', |
|
117 | + ]; |
|
118 | 118 | |
119 | - /** |
|
120 | - * The response's status code |
|
121 | - * |
|
122 | - * @var int |
|
123 | - */ |
|
124 | - private int $statusCode = self::STATUS_OK; |
|
119 | + /** |
|
120 | + * The response's status code |
|
121 | + * |
|
122 | + * @var int |
|
123 | + */ |
|
124 | + private int $statusCode = self::STATUS_OK; |
|
125 | 125 | |
126 | - /** |
|
127 | - * The response's reason phrase |
|
128 | - * |
|
129 | - * @var string |
|
130 | - */ |
|
131 | - private string $reasonPhrase = self::REASON_PHRASES[self::STATUS_OK]; |
|
126 | + /** |
|
127 | + * The response's reason phrase |
|
128 | + * |
|
129 | + * @var string |
|
130 | + */ |
|
131 | + private string $reasonPhrase = self::REASON_PHRASES[self::STATUS_OK]; |
|
132 | 132 | |
133 | - /** |
|
134 | - * Constrictor of the class |
|
135 | - * |
|
136 | - * @param int|null $statusCode |
|
137 | - * @param string|null $reasonPhrase |
|
138 | - * @param array<string, string|string[]>|null $headers |
|
139 | - * @param StreamInterface|null $body |
|
140 | - * |
|
141 | - * @throws InvalidArgumentException |
|
142 | - * If one of the arguments isn't valid. |
|
143 | - */ |
|
144 | - public function __construct( |
|
145 | - ?int $statusCode = null, |
|
146 | - ?string $reasonPhrase = null, |
|
147 | - ?array $headers = null, |
|
148 | - ?StreamInterface $body = null |
|
149 | - ) { |
|
150 | - if (isset($statusCode)) { |
|
151 | - $this->setStatus($statusCode, $reasonPhrase ?? ''); |
|
152 | - } |
|
133 | + /** |
|
134 | + * Constrictor of the class |
|
135 | + * |
|
136 | + * @param int|null $statusCode |
|
137 | + * @param string|null $reasonPhrase |
|
138 | + * @param array<string, string|string[]>|null $headers |
|
139 | + * @param StreamInterface|null $body |
|
140 | + * |
|
141 | + * @throws InvalidArgumentException |
|
142 | + * If one of the arguments isn't valid. |
|
143 | + */ |
|
144 | + public function __construct( |
|
145 | + ?int $statusCode = null, |
|
146 | + ?string $reasonPhrase = null, |
|
147 | + ?array $headers = null, |
|
148 | + ?StreamInterface $body = null |
|
149 | + ) { |
|
150 | + if (isset($statusCode)) { |
|
151 | + $this->setStatus($statusCode, $reasonPhrase ?? ''); |
|
152 | + } |
|
153 | 153 | |
154 | - if (isset($headers)) { |
|
155 | - $this->setHeaders($headers); |
|
156 | - } |
|
154 | + if (isset($headers)) { |
|
155 | + $this->setHeaders($headers); |
|
156 | + } |
|
157 | 157 | |
158 | - if (isset($body)) { |
|
159 | - $this->setBody($body); |
|
160 | - } |
|
161 | - } |
|
158 | + if (isset($body)) { |
|
159 | + $this->setBody($body); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Gets the response's status code |
|
165 | - * |
|
166 | - * @return int |
|
167 | - */ |
|
168 | - public function getStatusCode(): int |
|
169 | - { |
|
170 | - return $this->statusCode; |
|
171 | - } |
|
163 | + /** |
|
164 | + * Gets the response's status code |
|
165 | + * |
|
166 | + * @return int |
|
167 | + */ |
|
168 | + public function getStatusCode(): int |
|
169 | + { |
|
170 | + return $this->statusCode; |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Gets the response's reason phrase |
|
175 | - * |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public function getReasonPhrase(): string |
|
179 | - { |
|
180 | - return $this->reasonPhrase; |
|
181 | - } |
|
173 | + /** |
|
174 | + * Gets the response's reason phrase |
|
175 | + * |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public function getReasonPhrase(): string |
|
179 | + { |
|
180 | + return $this->reasonPhrase; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Creates a new instance of the response with the given status code |
|
185 | - * |
|
186 | - * @param int $code |
|
187 | - * @param string $reasonPhrase |
|
188 | - * |
|
189 | - * @return static |
|
190 | - * |
|
191 | - * @throws InvalidArgumentException |
|
192 | - * If the status isn't valid. |
|
193 | - */ |
|
194 | - public function withStatus($code, $reasonPhrase = ''): ResponseInterface |
|
195 | - { |
|
196 | - $clone = clone $this; |
|
197 | - $clone->setStatus($code, $reasonPhrase); |
|
183 | + /** |
|
184 | + * Creates a new instance of the response with the given status code |
|
185 | + * |
|
186 | + * @param int $code |
|
187 | + * @param string $reasonPhrase |
|
188 | + * |
|
189 | + * @return static |
|
190 | + * |
|
191 | + * @throws InvalidArgumentException |
|
192 | + * If the status isn't valid. |
|
193 | + */ |
|
194 | + public function withStatus($code, $reasonPhrase = ''): ResponseInterface |
|
195 | + { |
|
196 | + $clone = clone $this; |
|
197 | + $clone->setStatus($code, $reasonPhrase); |
|
198 | 198 | |
199 | - return $clone; |
|
200 | - } |
|
199 | + return $clone; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Sets the given status code to the response |
|
204 | - * |
|
205 | - * @param int $statusCode |
|
206 | - * @param string $reasonPhrase |
|
207 | - * |
|
208 | - * @return void |
|
209 | - * |
|
210 | - * @throws InvalidArgumentException |
|
211 | - * If the status isn't valid. |
|
212 | - */ |
|
213 | - final protected function setStatus($statusCode, $reasonPhrase): void |
|
214 | - { |
|
215 | - $this->validateStatusCode($statusCode); |
|
216 | - $this->validateReasonPhrase($reasonPhrase); |
|
202 | + /** |
|
203 | + * Sets the given status code to the response |
|
204 | + * |
|
205 | + * @param int $statusCode |
|
206 | + * @param string $reasonPhrase |
|
207 | + * |
|
208 | + * @return void |
|
209 | + * |
|
210 | + * @throws InvalidArgumentException |
|
211 | + * If the status isn't valid. |
|
212 | + */ |
|
213 | + final protected function setStatus($statusCode, $reasonPhrase): void |
|
214 | + { |
|
215 | + $this->validateStatusCode($statusCode); |
|
216 | + $this->validateReasonPhrase($reasonPhrase); |
|
217 | 217 | |
218 | - if ('' === $reasonPhrase) { |
|
219 | - $reasonPhrase = self::REASON_PHRASES[$statusCode] ?? 'Unknown Status Code'; |
|
220 | - } |
|
218 | + if ('' === $reasonPhrase) { |
|
219 | + $reasonPhrase = self::REASON_PHRASES[$statusCode] ?? 'Unknown Status Code'; |
|
220 | + } |
|
221 | 221 | |
222 | - $this->statusCode = $statusCode; |
|
223 | - $this->reasonPhrase = $reasonPhrase; |
|
224 | - } |
|
222 | + $this->statusCode = $statusCode; |
|
223 | + $this->reasonPhrase = $reasonPhrase; |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Validates the given status code |
|
228 | - * |
|
229 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
230 | - * |
|
231 | - * @param mixed $statusCode |
|
232 | - * |
|
233 | - * @return void |
|
234 | - * |
|
235 | - * @throws InvalidArgumentException |
|
236 | - * If the status code isn't valid. |
|
237 | - */ |
|
238 | - private function validateStatusCode($statusCode): void |
|
239 | - { |
|
240 | - if (!is_int($statusCode)) { |
|
241 | - throw new InvalidArgumentException('HTTP status code must be an integer'); |
|
242 | - } |
|
226 | + /** |
|
227 | + * Validates the given status code |
|
228 | + * |
|
229 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
230 | + * |
|
231 | + * @param mixed $statusCode |
|
232 | + * |
|
233 | + * @return void |
|
234 | + * |
|
235 | + * @throws InvalidArgumentException |
|
236 | + * If the status code isn't valid. |
|
237 | + */ |
|
238 | + private function validateStatusCode($statusCode): void |
|
239 | + { |
|
240 | + if (!is_int($statusCode)) { |
|
241 | + throw new InvalidArgumentException('HTTP status code must be an integer'); |
|
242 | + } |
|
243 | 243 | |
244 | - if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
245 | - throw new InvalidArgumentException('Invalid HTTP status code'); |
|
246 | - } |
|
247 | - } |
|
244 | + if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
245 | + throw new InvalidArgumentException('Invalid HTTP status code'); |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Validates the given reason phrase |
|
251 | - * |
|
252 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
253 | - * |
|
254 | - * @param mixed $reasonPhrase |
|
255 | - * |
|
256 | - * @return void |
|
257 | - * |
|
258 | - * @throws InvalidArgumentException |
|
259 | - * If the reason phrase isn't valid. |
|
260 | - */ |
|
261 | - private function validateReasonPhrase($reasonPhrase): void |
|
262 | - { |
|
263 | - if ('' === $reasonPhrase) { |
|
264 | - return; |
|
265 | - } |
|
249 | + /** |
|
250 | + * Validates the given reason phrase |
|
251 | + * |
|
252 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
253 | + * |
|
254 | + * @param mixed $reasonPhrase |
|
255 | + * |
|
256 | + * @return void |
|
257 | + * |
|
258 | + * @throws InvalidArgumentException |
|
259 | + * If the reason phrase isn't valid. |
|
260 | + */ |
|
261 | + private function validateReasonPhrase($reasonPhrase): void |
|
262 | + { |
|
263 | + if ('' === $reasonPhrase) { |
|
264 | + return; |
|
265 | + } |
|
266 | 266 | |
267 | - if (!is_string($reasonPhrase)) { |
|
268 | - throw new InvalidArgumentException('HTTP reason phrase must be a string'); |
|
269 | - } |
|
267 | + if (!is_string($reasonPhrase)) { |
|
268 | + throw new InvalidArgumentException('HTTP reason phrase must be a string'); |
|
269 | + } |
|
270 | 270 | |
271 | - if (!preg_match(HeaderInterface::RFC7230_FIELD_VALUE_REGEX, $reasonPhrase)) { |
|
272 | - throw new InvalidArgumentException('Invalid HTTP reason phrase'); |
|
273 | - } |
|
274 | - } |
|
271 | + if (!preg_match(HeaderInterface::RFC7230_FIELD_VALUE_REGEX, $reasonPhrase)) { |
|
272 | + throw new InvalidArgumentException('Invalid HTTP reason phrase'); |
|
273 | + } |
|
274 | + } |
|
275 | 275 | } |
@@ -22,52 +22,52 @@ |
||
22 | 22 | interface HeaderInterface extends IteratorAggregate |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Date format according to RFC-822 |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O'; |
|
25 | + /** |
|
26 | + * Date format according to RFC-822 |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Regular Expression used for a token validation according to RFC-7230 |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/'; |
|
32 | + /** |
|
33 | + * Regular Expression used for a token validation according to RFC-7230 |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Regular Expression used for a field-value validation according to RFC-7230 |
|
41 | - * |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/'; |
|
39 | + /** |
|
40 | + * Regular Expression used for a field-value validation according to RFC-7230 |
|
41 | + * |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/'; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Regular Expression used for a quoted-string validation according to RFC-7230 |
|
48 | - * |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/'; |
|
46 | + /** |
|
47 | + * Regular Expression used for a quoted-string validation according to RFC-7230 |
|
48 | + * |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/'; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Gets the header field name |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getFieldName(): string; |
|
53 | + /** |
|
54 | + * Gets the header field name |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getFieldName(): string; |
|
59 | 59 | |
60 | - /** |
|
61 | - * Gets the header field value |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getFieldValue(): string; |
|
60 | + /** |
|
61 | + * Gets the header field value |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getFieldValue(): string; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Converts the header to a field |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function __toString(): string; |
|
67 | + /** |
|
68 | + * Converts the header to a field |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function __toString(): string; |
|
73 | 73 | } |
@@ -28,14 +28,14 @@ |
||
28 | 28 | final class PhpTempStream extends Stream |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Constructor of the class |
|
33 | - * |
|
34 | - * @param string $mode |
|
35 | - * @param int<0, max> $maxmemory |
|
36 | - */ |
|
37 | - public function __construct(string $mode = 'r+b', int $maxmemory = 2097152) |
|
38 | - { |
|
39 | - parent::__construct(fopen(sprintf('php://temp/maxmemory:%d', $maxmemory), $mode)); |
|
40 | - } |
|
31 | + /** |
|
32 | + * Constructor of the class |
|
33 | + * |
|
34 | + * @param string $mode |
|
35 | + * @param int<0, max> $maxmemory |
|
36 | + */ |
|
37 | + public function __construct(string $mode = 'r+b', int $maxmemory = 2097152) |
|
38 | + { |
|
39 | + parent::__construct(fopen(sprintf('php://temp/maxmemory:%d', $maxmemory), $mode)); |
|
40 | + } |
|
41 | 41 | } |
@@ -32,30 +32,30 @@ |
||
32 | 32 | final class TempFileStream extends Stream |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Constructor of the class |
|
37 | - * |
|
38 | - * @param string $prefix |
|
39 | - * |
|
40 | - * @throws RuntimeException |
|
41 | - */ |
|
42 | - public function __construct(string $prefix = '') |
|
43 | - { |
|
44 | - $dirname = sys_get_temp_dir(); |
|
45 | - if (!is_writable($dirname)) { |
|
46 | - throw new RuntimeException('Temporary files directory is not writable'); |
|
47 | - } |
|
48 | - |
|
49 | - $filename = tempnam($dirname, $prefix); |
|
50 | - if ($filename === false) { |
|
51 | - throw new RuntimeException('Temporary file name cannot be generated'); |
|
52 | - } |
|
53 | - |
|
54 | - $resource = fopen($filename, 'w+b'); |
|
55 | - if (!is_resource($resource)) { |
|
56 | - throw new RuntimeException('Temporary file cannot be created or opened'); |
|
57 | - } |
|
58 | - |
|
59 | - parent::__construct($resource); |
|
60 | - } |
|
35 | + /** |
|
36 | + * Constructor of the class |
|
37 | + * |
|
38 | + * @param string $prefix |
|
39 | + * |
|
40 | + * @throws RuntimeException |
|
41 | + */ |
|
42 | + public function __construct(string $prefix = '') |
|
43 | + { |
|
44 | + $dirname = sys_get_temp_dir(); |
|
45 | + if (!is_writable($dirname)) { |
|
46 | + throw new RuntimeException('Temporary files directory is not writable'); |
|
47 | + } |
|
48 | + |
|
49 | + $filename = tempnam($dirname, $prefix); |
|
50 | + if ($filename === false) { |
|
51 | + throw new RuntimeException('Temporary file name cannot be generated'); |
|
52 | + } |
|
53 | + |
|
54 | + $resource = fopen($filename, 'w+b'); |
|
55 | + if (!is_resource($resource)) { |
|
56 | + throw new RuntimeException('Temporary file cannot be created or opened'); |
|
57 | + } |
|
58 | + |
|
59 | + parent::__construct($resource); |
|
60 | + } |
|
61 | 61 | } |