@@ -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 = $serverParams ?? $_SERVER; |
|
51 | - $queryParams = $queryParams ?? $_GET; |
|
52 | - $cookieParams = $cookieParams ?? $_COOKIE; |
|
53 | - $uploadedFiles = $uploadedFiles ?? $_FILES; |
|
54 | - $parsedBody = $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 = $serverParams ?? $_SERVER; |
|
51 | + $queryParams = $queryParams ?? $_GET; |
|
52 | + $cookieParams = $cookieParams ?? $_COOKIE; |
|
53 | + $uploadedFiles = $uploadedFiles ?? $_FILES; |
|
54 | + $parsedBody = $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 | } |
@@ -47,11 +47,11 @@ |
||
47 | 47 | ?array $uploadedFiles = null, |
48 | 48 | ?array $parsedBody = null |
49 | 49 | ): ServerRequestInterface { |
50 | - $serverParams = $serverParams ?? $_SERVER; |
|
51 | - $queryParams = $queryParams ?? $_GET; |
|
52 | - $cookieParams = $cookieParams ?? $_COOKIE; |
|
50 | + $serverParams = $serverParams ?? $_SERVER; |
|
51 | + $queryParams = $queryParams ?? $_GET; |
|
52 | + $cookieParams = $cookieParams ?? $_COOKIE; |
|
53 | 53 | $uploadedFiles = $uploadedFiles ?? $_FILES; |
54 | - $parsedBody = $parsedBody ?? $_POST; |
|
54 | + $parsedBody = $parsedBody ?? $_POST; |
|
55 | 55 | |
56 | 56 | return new ServerRequest( |
57 | 57 | server_request_protocol_version($serverParams), |
@@ -35,258 +35,258 @@ |
||
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, 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, 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 | - * Default response status code |
|
121 | - * |
|
122 | - * @var int |
|
123 | - */ |
|
124 | - public const DEFAULT_STATUS_CODE = self::STATUS_OK; |
|
119 | + /** |
|
120 | + * Default response status code |
|
121 | + * |
|
122 | + * @var int |
|
123 | + */ |
|
124 | + public const DEFAULT_STATUS_CODE = self::STATUS_OK; |
|
125 | 125 | |
126 | - /** |
|
127 | - * Default response reason phrase |
|
128 | - * |
|
129 | - * @var string |
|
130 | - */ |
|
131 | - public const DEFAULT_REASON_PHRASE = self::REASON_PHRASES[self::DEFAULT_STATUS_CODE]; |
|
126 | + /** |
|
127 | + * Default response reason phrase |
|
128 | + * |
|
129 | + * @var string |
|
130 | + */ |
|
131 | + public const DEFAULT_REASON_PHRASE = self::REASON_PHRASES[self::DEFAULT_STATUS_CODE]; |
|
132 | 132 | |
133 | - /** |
|
134 | - * Reason phrase for unknown status code |
|
135 | - * |
|
136 | - * @var string |
|
137 | - */ |
|
138 | - public const UNKNOWN_STATUS_CODE_REASON_PHRASE = 'Unknown Status Code'; |
|
133 | + /** |
|
134 | + * Reason phrase for unknown status code |
|
135 | + * |
|
136 | + * @var string |
|
137 | + */ |
|
138 | + public const UNKNOWN_STATUS_CODE_REASON_PHRASE = 'Unknown Status Code'; |
|
139 | 139 | |
140 | - /** |
|
141 | - * The response's status code |
|
142 | - * |
|
143 | - * @var int |
|
144 | - */ |
|
145 | - private int $statusCode = self::DEFAULT_STATUS_CODE; |
|
140 | + /** |
|
141 | + * The response's status code |
|
142 | + * |
|
143 | + * @var int |
|
144 | + */ |
|
145 | + private int $statusCode = self::DEFAULT_STATUS_CODE; |
|
146 | 146 | |
147 | - /** |
|
148 | - * The response's reason phrase |
|
149 | - * |
|
150 | - * @var string |
|
151 | - */ |
|
152 | - private string $reasonPhrase = self::DEFAULT_REASON_PHRASE; |
|
147 | + /** |
|
148 | + * The response's reason phrase |
|
149 | + * |
|
150 | + * @var string |
|
151 | + */ |
|
152 | + private string $reasonPhrase = self::DEFAULT_REASON_PHRASE; |
|
153 | 153 | |
154 | - /** |
|
155 | - * Constrictor of the class |
|
156 | - * |
|
157 | - * @param int|null $statusCode |
|
158 | - * @param string|null $reasonPhrase |
|
159 | - * @param array<string, string|string[]>|null $headers |
|
160 | - * @param StreamInterface|null $body |
|
161 | - * |
|
162 | - * @throws InvalidArgumentException |
|
163 | - * If one of the parameters isn't valid. |
|
164 | - */ |
|
165 | - public function __construct( |
|
166 | - ?int $statusCode = null, |
|
167 | - ?string $reasonPhrase = null, |
|
168 | - ?array $headers = null, |
|
169 | - ?StreamInterface $body = null |
|
170 | - ) { |
|
171 | - if (isset($statusCode)) { |
|
172 | - $this->setStatus($statusCode, $reasonPhrase ?? ''); |
|
173 | - } |
|
154 | + /** |
|
155 | + * Constrictor of the class |
|
156 | + * |
|
157 | + * @param int|null $statusCode |
|
158 | + * @param string|null $reasonPhrase |
|
159 | + * @param array<string, string|string[]>|null $headers |
|
160 | + * @param StreamInterface|null $body |
|
161 | + * |
|
162 | + * @throws InvalidArgumentException |
|
163 | + * If one of the parameters isn't valid. |
|
164 | + */ |
|
165 | + public function __construct( |
|
166 | + ?int $statusCode = null, |
|
167 | + ?string $reasonPhrase = null, |
|
168 | + ?array $headers = null, |
|
169 | + ?StreamInterface $body = null |
|
170 | + ) { |
|
171 | + if (isset($statusCode)) { |
|
172 | + $this->setStatus($statusCode, $reasonPhrase ?? ''); |
|
173 | + } |
|
174 | 174 | |
175 | - if (isset($headers)) { |
|
176 | - $this->setHeaders($headers); |
|
177 | - } |
|
175 | + if (isset($headers)) { |
|
176 | + $this->setHeaders($headers); |
|
177 | + } |
|
178 | 178 | |
179 | - if (isset($body)) { |
|
180 | - $this->setBody($body); |
|
181 | - } |
|
182 | - } |
|
179 | + if (isset($body)) { |
|
180 | + $this->setBody($body); |
|
181 | + } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Gets the response's status code |
|
186 | - * |
|
187 | - * @return int |
|
188 | - */ |
|
189 | - public function getStatusCode(): int |
|
190 | - { |
|
191 | - return $this->statusCode; |
|
192 | - } |
|
184 | + /** |
|
185 | + * Gets the response's status code |
|
186 | + * |
|
187 | + * @return int |
|
188 | + */ |
|
189 | + public function getStatusCode(): int |
|
190 | + { |
|
191 | + return $this->statusCode; |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * Gets the response's reason phrase |
|
196 | - * |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function getReasonPhrase(): string |
|
200 | - { |
|
201 | - return $this->reasonPhrase; |
|
202 | - } |
|
194 | + /** |
|
195 | + * Gets the response's reason phrase |
|
196 | + * |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function getReasonPhrase(): string |
|
200 | + { |
|
201 | + return $this->reasonPhrase; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Creates a new instance of the response with the given status code |
|
206 | - * |
|
207 | - * @param int $code |
|
208 | - * @param string $reasonPhrase |
|
209 | - * |
|
210 | - * @return static |
|
211 | - * |
|
212 | - * @throws InvalidArgumentException |
|
213 | - * If the status isn't valid. |
|
214 | - */ |
|
215 | - public function withStatus($code, $reasonPhrase = ''): ResponseInterface |
|
216 | - { |
|
217 | - $clone = clone $this; |
|
218 | - $clone->setStatus($code, $reasonPhrase); |
|
204 | + /** |
|
205 | + * Creates a new instance of the response with the given status code |
|
206 | + * |
|
207 | + * @param int $code |
|
208 | + * @param string $reasonPhrase |
|
209 | + * |
|
210 | + * @return static |
|
211 | + * |
|
212 | + * @throws InvalidArgumentException |
|
213 | + * If the status isn't valid. |
|
214 | + */ |
|
215 | + public function withStatus($code, $reasonPhrase = ''): ResponseInterface |
|
216 | + { |
|
217 | + $clone = clone $this; |
|
218 | + $clone->setStatus($code, $reasonPhrase); |
|
219 | 219 | |
220 | - return $clone; |
|
221 | - } |
|
220 | + return $clone; |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * Sets the given status code to the response |
|
225 | - * |
|
226 | - * @param int $statusCode |
|
227 | - * @param string $reasonPhrase |
|
228 | - * |
|
229 | - * @return void |
|
230 | - * |
|
231 | - * @throws InvalidArgumentException |
|
232 | - * If the status isn't valid. |
|
233 | - */ |
|
234 | - final protected function setStatus($statusCode, $reasonPhrase): void |
|
235 | - { |
|
236 | - $this->validateStatusCode($statusCode); |
|
237 | - $this->validateReasonPhrase($reasonPhrase); |
|
223 | + /** |
|
224 | + * Sets the given status code to the response |
|
225 | + * |
|
226 | + * @param int $statusCode |
|
227 | + * @param string $reasonPhrase |
|
228 | + * |
|
229 | + * @return void |
|
230 | + * |
|
231 | + * @throws InvalidArgumentException |
|
232 | + * If the status isn't valid. |
|
233 | + */ |
|
234 | + final protected function setStatus($statusCode, $reasonPhrase): void |
|
235 | + { |
|
236 | + $this->validateStatusCode($statusCode); |
|
237 | + $this->validateReasonPhrase($reasonPhrase); |
|
238 | 238 | |
239 | - if ('' === $reasonPhrase) { |
|
240 | - $reasonPhrase = self::REASON_PHRASES[$statusCode] ?? self::UNKNOWN_STATUS_CODE_REASON_PHRASE; |
|
241 | - } |
|
239 | + if ('' === $reasonPhrase) { |
|
240 | + $reasonPhrase = self::REASON_PHRASES[$statusCode] ?? self::UNKNOWN_STATUS_CODE_REASON_PHRASE; |
|
241 | + } |
|
242 | 242 | |
243 | - $this->statusCode = $statusCode; |
|
244 | - $this->reasonPhrase = $reasonPhrase; |
|
245 | - } |
|
243 | + $this->statusCode = $statusCode; |
|
244 | + $this->reasonPhrase = $reasonPhrase; |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * Validates the given status code |
|
249 | - * |
|
250 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
251 | - * |
|
252 | - * @param mixed $statusCode |
|
253 | - * |
|
254 | - * @return void |
|
255 | - * |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * If the status code isn't valid. |
|
258 | - */ |
|
259 | - private function validateStatusCode($statusCode): void |
|
260 | - { |
|
261 | - if (!is_int($statusCode)) { |
|
262 | - throw new InvalidArgumentException('HTTP status code must be an integer'); |
|
263 | - } |
|
247 | + /** |
|
248 | + * Validates the given status code |
|
249 | + * |
|
250 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
251 | + * |
|
252 | + * @param mixed $statusCode |
|
253 | + * |
|
254 | + * @return void |
|
255 | + * |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * If the status code isn't valid. |
|
258 | + */ |
|
259 | + private function validateStatusCode($statusCode): void |
|
260 | + { |
|
261 | + if (!is_int($statusCode)) { |
|
262 | + throw new InvalidArgumentException('HTTP status code must be an integer'); |
|
263 | + } |
|
264 | 264 | |
265 | - if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
266 | - throw new InvalidArgumentException('Invalid HTTP status code'); |
|
267 | - } |
|
268 | - } |
|
265 | + if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
266 | + throw new InvalidArgumentException('Invalid HTTP status code'); |
|
267 | + } |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Validates the given reason phrase |
|
272 | - * |
|
273 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
274 | - * |
|
275 | - * @param mixed $reasonPhrase |
|
276 | - * |
|
277 | - * @return void |
|
278 | - * |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * If the reason phrase isn't valid. |
|
281 | - */ |
|
282 | - private function validateReasonPhrase($reasonPhrase): void |
|
283 | - { |
|
284 | - if (!is_string($reasonPhrase)) { |
|
285 | - throw new InvalidArgumentException('HTTP reason phrase must be a string'); |
|
286 | - } |
|
270 | + /** |
|
271 | + * Validates the given reason phrase |
|
272 | + * |
|
273 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
274 | + * |
|
275 | + * @param mixed $reasonPhrase |
|
276 | + * |
|
277 | + * @return void |
|
278 | + * |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * If the reason phrase isn't valid. |
|
281 | + */ |
|
282 | + private function validateReasonPhrase($reasonPhrase): void |
|
283 | + { |
|
284 | + if (!is_string($reasonPhrase)) { |
|
285 | + throw new InvalidArgumentException('HTTP reason phrase must be a string'); |
|
286 | + } |
|
287 | 287 | |
288 | - if (!preg_match(Header::RFC7230_VALID_FIELD_VALUE, $reasonPhrase)) { |
|
289 | - throw new InvalidArgumentException('Invalid HTTP reason phrase'); |
|
290 | - } |
|
291 | - } |
|
288 | + if (!preg_match(Header::RFC7230_VALID_FIELD_VALUE, $reasonPhrase)) { |
|
289 | + throw new InvalidArgumentException('Invalid HTTP reason phrase'); |
|
290 | + } |
|
291 | + } |
|
292 | 292 | } |
@@ -262,7 +262,7 @@ |
||
262 | 262 | throw new InvalidArgumentException('HTTP status code must be an integer'); |
263 | 263 | } |
264 | 264 | |
265 | - if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
265 | + if (!($statusCode >= 100 && $statusCode <= 599)) { |
|
266 | 266 | throw new InvalidArgumentException('Invalid HTTP status code'); |
267 | 267 | } |
268 | 268 | } |
@@ -27,35 +27,35 @@ |
||
27 | 27 | class StreamFactory implements StreamFactoryInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public function createStream(string $content = ''): StreamInterface |
|
34 | - { |
|
35 | - $stream = new PhpTempStream(); |
|
36 | - if ($content === '') { |
|
37 | - return $stream; |
|
38 | - } |
|
39 | - |
|
40 | - $stream->write($content); |
|
41 | - $stream->rewind(); |
|
42 | - |
|
43 | - return $stream; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * {@inheritdoc} |
|
48 | - */ |
|
49 | - public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface |
|
50 | - { |
|
51 | - return new FileStream($filename, $mode); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - public function createStreamFromResource($resource): StreamInterface |
|
58 | - { |
|
59 | - return new Stream($resource); |
|
60 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public function createStream(string $content = ''): StreamInterface |
|
34 | + { |
|
35 | + $stream = new PhpTempStream(); |
|
36 | + if ($content === '') { |
|
37 | + return $stream; |
|
38 | + } |
|
39 | + |
|
40 | + $stream->write($content); |
|
41 | + $stream->rewind(); |
|
42 | + |
|
43 | + return $stream; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * {@inheritdoc} |
|
48 | + */ |
|
49 | + public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface |
|
50 | + { |
|
51 | + return new FileStream($filename, $mode); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + public function createStreamFromResource($resource): StreamInterface |
|
58 | + { |
|
59 | + return new Stream($resource); |
|
60 | + } |
|
61 | 61 | } |
@@ -25,11 +25,11 @@ |
||
25 | 25 | class UriFactory implements UriFactoryInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - public function createUri(string $uri = ''): UriInterface |
|
32 | - { |
|
33 | - return new Uri($uri); |
|
34 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + public function createUri(string $uri = ''): UriInterface |
|
32 | + { |
|
33 | + return new Uri($uri); |
|
34 | + } |
|
35 | 35 | } |
@@ -17,11 +17,11 @@ |
||
17 | 17 | class InvalidStreamException extends RuntimeException |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @return self |
|
22 | - */ |
|
23 | - final public static function noResource(): self |
|
24 | - { |
|
25 | - return new self('The stream without a resource so the operation is not possible'); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return self |
|
22 | + */ |
|
23 | + final public static function noResource(): self |
|
24 | + { |
|
25 | + return new self('The stream without a resource so the operation is not possible'); |
|
26 | + } |
|
27 | 27 | } |
@@ -26,26 +26,26 @@ |
||
26 | 26 | interface HeaderInterface extends IteratorAggregate |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Gets the header field name |
|
31 | - * |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function getFieldName(): string; |
|
29 | + /** |
|
30 | + * Gets the header field name |
|
31 | + * |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function getFieldName(): string; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Gets the header field value |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function getFieldValue(): string; |
|
36 | + /** |
|
37 | + * Gets the header field value |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function getFieldValue(): string; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Converts the header field to a string |
|
45 | - * |
|
46 | - * @link http://php.net/manual/en/language.oop5.magic.php#object.tostring |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function __toString(): string; |
|
43 | + /** |
|
44 | + * Converts the header field to a string |
|
45 | + * |
|
46 | + * @link http://php.net/manual/en/language.oop5.magic.php#object.tostring |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function __toString(): string; |
|
51 | 51 | } |
@@ -25,11 +25,11 @@ |
||
25 | 25 | class RequestFactory implements RequestFactoryInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - public function createRequest(string $method, $uri): RequestInterface |
|
32 | - { |
|
33 | - return new Request($method, $uri); |
|
34 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + public function createRequest(string $method, $uri): RequestInterface |
|
32 | + { |
|
33 | + return new Request($method, $uri); |
|
34 | + } |
|
35 | 35 | } |
@@ -38,221 +38,221 @@ |
||
38 | 38 | abstract class Header implements HeaderInterface |
39 | 39 | { |
40 | 40 | |
41 | - /** |
|
42 | - * Regular Expression for a token validation |
|
43 | - * |
|
44 | - * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - public const RFC7230_VALID_TOKEN = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/'; |
|
41 | + /** |
|
42 | + * Regular Expression for a token validation |
|
43 | + * |
|
44 | + * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + public const RFC7230_VALID_TOKEN = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/'; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Regular Expression for a field value validation |
|
52 | - * |
|
53 | - * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public const RFC7230_VALID_FIELD_VALUE = '/^[\x09\x20-\x7E\x80-\xFF]*$/'; |
|
50 | + /** |
|
51 | + * Regular Expression for a field value validation |
|
52 | + * |
|
53 | + * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public const RFC7230_VALID_FIELD_VALUE = '/^[\x09\x20-\x7E\x80-\xFF]*$/'; |
|
58 | 58 | |
59 | - /** |
|
60 | - * Regular Expression for a quoted string validation |
|
61 | - * |
|
62 | - * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public const RFC7230_VALID_QUOTED_STRING = '/^[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF]*$/'; |
|
59 | + /** |
|
60 | + * Regular Expression for a quoted string validation |
|
61 | + * |
|
62 | + * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public const RFC7230_VALID_QUOTED_STRING = '/^[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF]*$/'; |
|
67 | 67 | |
68 | - /** |
|
69 | - * Date and time format |
|
70 | - * |
|
71 | - * @link https://www.rfc-editor.org/rfc/rfc822#section-5 |
|
72 | - * |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public const RFC822_DATE_TIME_FORMAT = 'D, d M y H:i:s O'; |
|
68 | + /** |
|
69 | + * Date and time format |
|
70 | + * |
|
71 | + * @link https://www.rfc-editor.org/rfc/rfc822#section-5 |
|
72 | + * |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public const RFC822_DATE_TIME_FORMAT = 'D, d M y H:i:s O'; |
|
76 | 76 | |
77 | - /** |
|
78 | - * {@inheritdoc} |
|
79 | - */ |
|
80 | - final public function getIterator(): Traversable |
|
81 | - { |
|
82 | - return new ArrayIterator([$this->getFieldName(), $this->getFieldValue()]); |
|
83 | - } |
|
77 | + /** |
|
78 | + * {@inheritdoc} |
|
79 | + */ |
|
80 | + final public function getIterator(): Traversable |
|
81 | + { |
|
82 | + return new ArrayIterator([$this->getFieldName(), $this->getFieldValue()]); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * {@inheritdoc} |
|
87 | - */ |
|
88 | - final public function __toString(): string |
|
89 | - { |
|
90 | - return sprintf('%s: %s', $this->getFieldName(), $this->getFieldValue()); |
|
91 | - } |
|
85 | + /** |
|
86 | + * {@inheritdoc} |
|
87 | + */ |
|
88 | + final public function __toString(): string |
|
89 | + { |
|
90 | + return sprintf('%s: %s', $this->getFieldName(), $this->getFieldValue()); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Checks if the given string is a token |
|
95 | - * |
|
96 | - * @param string $token |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - final protected function isToken(string $token): bool |
|
101 | - { |
|
102 | - return preg_match(self::RFC7230_VALID_TOKEN, $token) === 1; |
|
103 | - } |
|
93 | + /** |
|
94 | + * Checks if the given string is a token |
|
95 | + * |
|
96 | + * @param string $token |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + final protected function isToken(string $token): bool |
|
101 | + { |
|
102 | + return preg_match(self::RFC7230_VALID_TOKEN, $token) === 1; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Validates the given token(s) |
|
107 | - * |
|
108 | - * @param string ...$tokens |
|
109 | - * |
|
110 | - * @return void |
|
111 | - * |
|
112 | - * @throws InvalidHeaderValueException |
|
113 | - * If one of the tokens isn't valid. |
|
114 | - */ |
|
115 | - final protected function validateToken(string ...$tokens): void |
|
116 | - { |
|
117 | - $this->validateValueByRegex(self::RFC7230_VALID_TOKEN, ...$tokens); |
|
118 | - } |
|
105 | + /** |
|
106 | + * Validates the given token(s) |
|
107 | + * |
|
108 | + * @param string ...$tokens |
|
109 | + * |
|
110 | + * @return void |
|
111 | + * |
|
112 | + * @throws InvalidHeaderValueException |
|
113 | + * If one of the tokens isn't valid. |
|
114 | + */ |
|
115 | + final protected function validateToken(string ...$tokens): void |
|
116 | + { |
|
117 | + $this->validateValueByRegex(self::RFC7230_VALID_TOKEN, ...$tokens); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Validates the given field value(s) |
|
122 | - * |
|
123 | - * @param string ...$fieldValues |
|
124 | - * |
|
125 | - * @return void |
|
126 | - * |
|
127 | - * @throws InvalidHeaderValueException |
|
128 | - * If one of the field values isn't valid. |
|
129 | - */ |
|
130 | - final protected function validateFieldValue(string ...$fieldValues): void |
|
131 | - { |
|
132 | - $this->validateValueByRegex(self::RFC7230_VALID_FIELD_VALUE, ...$fieldValues); |
|
133 | - } |
|
120 | + /** |
|
121 | + * Validates the given field value(s) |
|
122 | + * |
|
123 | + * @param string ...$fieldValues |
|
124 | + * |
|
125 | + * @return void |
|
126 | + * |
|
127 | + * @throws InvalidHeaderValueException |
|
128 | + * If one of the field values isn't valid. |
|
129 | + */ |
|
130 | + final protected function validateFieldValue(string ...$fieldValues): void |
|
131 | + { |
|
132 | + $this->validateValueByRegex(self::RFC7230_VALID_FIELD_VALUE, ...$fieldValues); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Validates the given quoted string(s) |
|
137 | - * |
|
138 | - * @param string ...$quotedStrings |
|
139 | - * |
|
140 | - * @return void |
|
141 | - * |
|
142 | - * @throws InvalidHeaderValueException |
|
143 | - * If one of the quoted strings isn't valid. |
|
144 | - */ |
|
145 | - final protected function validateQuotedString(string ...$quotedStrings): void |
|
146 | - { |
|
147 | - $this->validateValueByRegex(self::RFC7230_VALID_QUOTED_STRING, ...$quotedStrings); |
|
148 | - } |
|
135 | + /** |
|
136 | + * Validates the given quoted string(s) |
|
137 | + * |
|
138 | + * @param string ...$quotedStrings |
|
139 | + * |
|
140 | + * @return void |
|
141 | + * |
|
142 | + * @throws InvalidHeaderValueException |
|
143 | + * If one of the quoted strings isn't valid. |
|
144 | + */ |
|
145 | + final protected function validateQuotedString(string ...$quotedStrings): void |
|
146 | + { |
|
147 | + $this->validateValueByRegex(self::RFC7230_VALID_QUOTED_STRING, ...$quotedStrings); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Validates and normalizes the given parameters |
|
152 | - * |
|
153 | - * @param array<array-key, mixed> $parameters |
|
154 | - * |
|
155 | - * @return array<string, string> |
|
156 | - * The normalized parameters. |
|
157 | - * |
|
158 | - * @throws InvalidHeaderValueParameterException |
|
159 | - * If one of the parameters isn't valid. |
|
160 | - */ |
|
161 | - final protected function validateParameters(array $parameters): array |
|
162 | - { |
|
163 | - return $this->validateParametersByRegex( |
|
164 | - $parameters, |
|
165 | - self::RFC7230_VALID_TOKEN, |
|
166 | - self::RFC7230_VALID_QUOTED_STRING |
|
167 | - ); |
|
168 | - } |
|
150 | + /** |
|
151 | + * Validates and normalizes the given parameters |
|
152 | + * |
|
153 | + * @param array<array-key, mixed> $parameters |
|
154 | + * |
|
155 | + * @return array<string, string> |
|
156 | + * The normalized parameters. |
|
157 | + * |
|
158 | + * @throws InvalidHeaderValueParameterException |
|
159 | + * If one of the parameters isn't valid. |
|
160 | + */ |
|
161 | + final protected function validateParameters(array $parameters): array |
|
162 | + { |
|
163 | + return $this->validateParametersByRegex( |
|
164 | + $parameters, |
|
165 | + self::RFC7230_VALID_TOKEN, |
|
166 | + self::RFC7230_VALID_QUOTED_STRING |
|
167 | + ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Validates the given value(s) by the given regular expression |
|
172 | - * |
|
173 | - * @param string $regex |
|
174 | - * @param string ...$values |
|
175 | - * |
|
176 | - * @return void |
|
177 | - * |
|
178 | - * @throws InvalidHeaderValueException |
|
179 | - * If one of the values isn't valid. |
|
180 | - */ |
|
181 | - final protected function validateValueByRegex(string $regex, string ...$values): void |
|
182 | - { |
|
183 | - foreach ($values as $value) { |
|
184 | - if (!preg_match($regex, $value)) { |
|
185 | - throw new InvalidHeaderValueException(sprintf( |
|
186 | - 'The value "%2$s" for the header "%1$s" is not valid', |
|
187 | - $this->getFieldName(), |
|
188 | - $value |
|
189 | - )); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
170 | + /** |
|
171 | + * Validates the given value(s) by the given regular expression |
|
172 | + * |
|
173 | + * @param string $regex |
|
174 | + * @param string ...$values |
|
175 | + * |
|
176 | + * @return void |
|
177 | + * |
|
178 | + * @throws InvalidHeaderValueException |
|
179 | + * If one of the values isn't valid. |
|
180 | + */ |
|
181 | + final protected function validateValueByRegex(string $regex, string ...$values): void |
|
182 | + { |
|
183 | + foreach ($values as $value) { |
|
184 | + if (!preg_match($regex, $value)) { |
|
185 | + throw new InvalidHeaderValueException(sprintf( |
|
186 | + 'The value "%2$s" for the header "%1$s" is not valid', |
|
187 | + $this->getFieldName(), |
|
188 | + $value |
|
189 | + )); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * Validates and normalizes the given parameters by the given regular expressions |
|
196 | - * |
|
197 | - * @param array<array-key, mixed> $parameters |
|
198 | - * @param string $nameRegex |
|
199 | - * @param string $valueRegex |
|
200 | - * |
|
201 | - * @return array<string, string> |
|
202 | - * The normalized parameters. |
|
203 | - * |
|
204 | - * @throws InvalidHeaderValueParameterException |
|
205 | - * If one of the parameters isn't valid. |
|
206 | - */ |
|
207 | - final protected function validateParametersByRegex(array $parameters, string $nameRegex, string $valueRegex): array |
|
208 | - { |
|
209 | - foreach ($parameters as $name => &$value) { |
|
210 | - if (!is_string($name) || !preg_match($nameRegex, $name)) { |
|
211 | - throw new InvalidHeaderValueParameterException(sprintf( |
|
212 | - 'The parameter name "%2$s" for the header "%1$s" is not valid', |
|
213 | - $this->getFieldName(), |
|
214 | - (is_string($name) ? $name : ('<' . gettype($name) . '>')) |
|
215 | - )); |
|
216 | - } |
|
194 | + /** |
|
195 | + * Validates and normalizes the given parameters by the given regular expressions |
|
196 | + * |
|
197 | + * @param array<array-key, mixed> $parameters |
|
198 | + * @param string $nameRegex |
|
199 | + * @param string $valueRegex |
|
200 | + * |
|
201 | + * @return array<string, string> |
|
202 | + * The normalized parameters. |
|
203 | + * |
|
204 | + * @throws InvalidHeaderValueParameterException |
|
205 | + * If one of the parameters isn't valid. |
|
206 | + */ |
|
207 | + final protected function validateParametersByRegex(array $parameters, string $nameRegex, string $valueRegex): array |
|
208 | + { |
|
209 | + foreach ($parameters as $name => &$value) { |
|
210 | + if (!is_string($name) || !preg_match($nameRegex, $name)) { |
|
211 | + throw new InvalidHeaderValueParameterException(sprintf( |
|
212 | + 'The parameter name "%2$s" for the header "%1$s" is not valid', |
|
213 | + $this->getFieldName(), |
|
214 | + (is_string($name) ? $name : ('<' . gettype($name) . '>')) |
|
215 | + )); |
|
216 | + } |
|
217 | 217 | |
218 | - // e.g. Cache-Control: max-age=31536000 |
|
219 | - if (is_int($value)) { |
|
220 | - $value = (string) $value; |
|
221 | - } |
|
218 | + // e.g. Cache-Control: max-age=31536000 |
|
219 | + if (is_int($value)) { |
|
220 | + $value = (string) $value; |
|
221 | + } |
|
222 | 222 | |
223 | - if (!is_string($value) || !preg_match($valueRegex, $value)) { |
|
224 | - throw new InvalidHeaderValueParameterException(sprintf( |
|
225 | - 'The parameter value "%2$s" for the header "%1$s" is not valid', |
|
226 | - $this->getFieldName(), |
|
227 | - (is_string($value) ? $value : ('<' . gettype($value) . '>')) |
|
228 | - )); |
|
229 | - } |
|
230 | - } |
|
223 | + if (!is_string($value) || !preg_match($valueRegex, $value)) { |
|
224 | + throw new InvalidHeaderValueParameterException(sprintf( |
|
225 | + 'The parameter value "%2$s" for the header "%1$s" is not valid', |
|
226 | + $this->getFieldName(), |
|
227 | + (is_string($value) ? $value : ('<' . gettype($value) . '>')) |
|
228 | + )); |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - /** @var array<string, string> $parameters */ |
|
232 | + /** @var array<string, string> $parameters */ |
|
233 | 233 | |
234 | - return $parameters; |
|
235 | - } |
|
234 | + return $parameters; |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * Formats the given date-time object |
|
239 | - * |
|
240 | - * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
241 | - * |
|
242 | - * @param DateTimeInterface $dateTime |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - final protected function formatDateTime(DateTimeInterface $dateTime): string |
|
247 | - { |
|
248 | - if ($dateTime instanceof DateTime) { |
|
249 | - return (clone $dateTime) |
|
250 | - ->setTimezone(new DateTimeZone('GMT')) |
|
251 | - ->format(self::RFC822_DATE_TIME_FORMAT); |
|
252 | - } |
|
237 | + /** |
|
238 | + * Formats the given date-time object |
|
239 | + * |
|
240 | + * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
241 | + * |
|
242 | + * @param DateTimeInterface $dateTime |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + final protected function formatDateTime(DateTimeInterface $dateTime): string |
|
247 | + { |
|
248 | + if ($dateTime instanceof DateTime) { |
|
249 | + return (clone $dateTime) |
|
250 | + ->setTimezone(new DateTimeZone('GMT')) |
|
251 | + ->format(self::RFC822_DATE_TIME_FORMAT); |
|
252 | + } |
|
253 | 253 | |
254 | - return $dateTime |
|
255 | - ->setTimezone(new DateTimeZone('GMT')) |
|
256 | - ->format(self::RFC822_DATE_TIME_FORMAT); |
|
257 | - } |
|
254 | + return $dateTime |
|
255 | + ->setTimezone(new DateTimeZone('GMT')) |
|
256 | + ->format(self::RFC822_DATE_TIME_FORMAT); |
|
257 | + } |
|
258 | 258 | } |
@@ -31,53 +31,53 @@ |
||
31 | 31 | final class Scheme implements ComponentInterface |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Regular expression to validate the component value |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private const VALIDATE_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\+\-\.]*)?$/'; |
|
34 | + /** |
|
35 | + * Regular expression to validate the component value |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private const VALIDATE_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\+\-\.]*)?$/'; |
|
40 | 40 | |
41 | - /** |
|
42 | - * The component value |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - private string $value = ''; |
|
41 | + /** |
|
42 | + * The component value |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + private string $value = ''; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Constructor of the class |
|
50 | - * |
|
51 | - * @param mixed $value |
|
52 | - * |
|
53 | - * @throws InvalidUriComponentException |
|
54 | - * If the component isn't valid. |
|
55 | - */ |
|
56 | - public function __construct($value) |
|
57 | - { |
|
58 | - if ($value === '') { |
|
59 | - return; |
|
60 | - } |
|
48 | + /** |
|
49 | + * Constructor of the class |
|
50 | + * |
|
51 | + * @param mixed $value |
|
52 | + * |
|
53 | + * @throws InvalidUriComponentException |
|
54 | + * If the component isn't valid. |
|
55 | + */ |
|
56 | + public function __construct($value) |
|
57 | + { |
|
58 | + if ($value === '') { |
|
59 | + return; |
|
60 | + } |
|
61 | 61 | |
62 | - if (!is_string($value)) { |
|
63 | - throw new InvalidUriComponentException('URI component "scheme" must be a string'); |
|
64 | - } |
|
62 | + if (!is_string($value)) { |
|
63 | + throw new InvalidUriComponentException('URI component "scheme" must be a string'); |
|
64 | + } |
|
65 | 65 | |
66 | - if (!preg_match(self::VALIDATE_REGEX, $value)) { |
|
67 | - throw new InvalidUriComponentException('Invalid URI component "scheme"'); |
|
68 | - } |
|
66 | + if (!preg_match(self::VALIDATE_REGEX, $value)) { |
|
67 | + throw new InvalidUriComponentException('Invalid URI component "scheme"'); |
|
68 | + } |
|
69 | 69 | |
70 | - // the component is case-insensitive... |
|
71 | - $this->value = strtolower($value); |
|
72 | - } |
|
70 | + // the component is case-insensitive... |
|
71 | + $this->value = strtolower($value); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * {@inheritdoc} |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getValue(): string |
|
80 | - { |
|
81 | - return $this->value; |
|
82 | - } |
|
74 | + /** |
|
75 | + * {@inheritdoc} |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getValue(): string |
|
80 | + { |
|
81 | + return $this->value; |
|
82 | + } |
|
83 | 83 | } |