@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function withHeader($name, $value): self |
64 | 64 | { |
65 | 65 | $name = strtolower($name); |
66 | - $this->headers[$name] = $this->validateAndTrimHeader($name, (array)$value); |
|
66 | + $this->headers[$name] = $this->validateAndTrimHeader($name, (array) $value); |
|
67 | 67 | return $this; |
68 | 68 | } |
69 | 69 | |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | |
109 | 109 | $returnValues = []; |
110 | 110 | foreach ($values as $v) { |
111 | - if ((!is_numeric($v) && !is_string($v)) || 1 !== preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string)$v)) { |
|
111 | + if ((!is_numeric($v) && !is_string($v)) || 1 !== preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $v)) { |
|
112 | 112 | throw new InvalidArgumentException('Header values must be RFC 7230 compatible strings.'); |
113 | 113 | } |
114 | 114 | |
115 | - $returnValues[] = trim((string)$v); |
|
115 | + $returnValues[] = trim((string) $v); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return $returnValues; |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | protected function setHeaders(array $headers): void |
128 | 128 | { |
129 | 129 | foreach ($headers as $name => $values) { |
130 | - $values = (array)$values; |
|
131 | - $name = strtolower((string)$name); |
|
130 | + $values = (array) $values; |
|
131 | + $name = strtolower((string) $name); |
|
132 | 132 | |
133 | 133 | if (!$this->hasHeader($name)) { |
134 | 134 | $this->headers[$name] = []; |
@@ -14,131 +14,131 @@ |
||
14 | 14 | class Message implements MessageInterface |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * RFC-2616, RFC-7230 - case-insensitive; HTTP2 pack convert all header to lowercase |
|
19 | - * |
|
20 | - * @var array - all header name will be convert to lowercase |
|
21 | - */ |
|
22 | - protected array $headers = []; |
|
23 | - protected string $protocol = '1.1'; |
|
24 | - protected ?StreamInterface $stream = null; |
|
25 | - |
|
26 | - public function getProtocolVersion(): string |
|
27 | - { |
|
28 | - return $this->protocol; |
|
29 | - } |
|
30 | - |
|
31 | - public function withProtocolVersion($version): self |
|
32 | - { |
|
33 | - if ($this->protocol !== $version) { |
|
34 | - $this->protocol = $version; |
|
35 | - } |
|
36 | - |
|
37 | - return $this; |
|
38 | - } |
|
39 | - |
|
40 | - public function getHeaders(): array |
|
41 | - { |
|
42 | - return $this->headers; |
|
43 | - } |
|
44 | - |
|
45 | - public function hasHeader($name): bool |
|
46 | - { |
|
47 | - $name = strtolower($name); |
|
48 | - $hasHeader = $this->headers[$name] ?? null; |
|
49 | - return $hasHeader !== null; |
|
50 | - } |
|
51 | - |
|
52 | - public function getHeader($name): array |
|
53 | - { |
|
54 | - $name = strtolower($name); |
|
55 | - return $this->headers[$name] ?? []; |
|
56 | - } |
|
57 | - |
|
58 | - public function getHeaderLine($name): string |
|
59 | - { |
|
60 | - return implode(', ', $this->getHeader($name)); |
|
61 | - } |
|
62 | - |
|
63 | - public function withHeader($name, $value): self |
|
64 | - { |
|
65 | - $name = strtolower($name); |
|
66 | - $this->headers[$name] = $this->validateAndTrimHeader($name, (array)$value); |
|
67 | - return $this; |
|
68 | - } |
|
69 | - |
|
70 | - public function withoutHeader($name): self |
|
71 | - { |
|
72 | - $name = strtolower($name); |
|
73 | - unset($this->headers[$name]); |
|
74 | - return $this; |
|
75 | - } |
|
76 | - |
|
77 | - public function getBody(): StreamInterface |
|
78 | - { |
|
79 | - if (!$this->stream) { |
|
80 | - $this->stream = Stream::create(''); |
|
81 | - } |
|
82 | - |
|
83 | - return $this->stream; |
|
84 | - } |
|
85 | - |
|
86 | - public function withBody(StreamInterface $body): self |
|
87 | - { |
|
88 | - $this->stream = $body; |
|
89 | - return $this; |
|
90 | - } |
|
91 | - |
|
92 | - public function reset(): static |
|
93 | - { |
|
94 | - $this->headers = []; |
|
95 | - if ($this->stream) { |
|
96 | - $this->stream->close(); |
|
97 | - $this->stream = null; |
|
98 | - } |
|
99 | - |
|
100 | - return $this; |
|
101 | - } |
|
102 | - |
|
103 | - protected function validateAndTrimHeader(string $name, array $values): array |
|
104 | - { |
|
105 | - if (preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@", $name) !== 1) { |
|
106 | - throw new InvalidArgumentException('Header name must be an RFC 7230 compatible string.'); |
|
107 | - } |
|
108 | - |
|
109 | - $returnValues = []; |
|
110 | - foreach ($values as $v) { |
|
111 | - if ((!is_numeric($v) && !is_string($v)) || 1 !== preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string)$v)) { |
|
112 | - throw new InvalidArgumentException('Header values must be RFC 7230 compatible strings.'); |
|
113 | - } |
|
114 | - |
|
115 | - $returnValues[] = trim((string)$v); |
|
116 | - } |
|
117 | - |
|
118 | - return $returnValues; |
|
119 | - } |
|
120 | - |
|
121 | - public function withAddedHeader($name, $value): self |
|
122 | - { |
|
123 | - $this->setHeaders([$name => $value]); |
|
124 | - return $this; |
|
125 | - } |
|
126 | - |
|
127 | - protected function setHeaders(array $headers): void |
|
128 | - { |
|
129 | - foreach ($headers as $name => $values) { |
|
130 | - $values = (array)$values; |
|
131 | - $name = strtolower((string)$name); |
|
132 | - |
|
133 | - if (!$this->hasHeader($name)) { |
|
134 | - $this->headers[$name] = []; |
|
135 | - } |
|
136 | - |
|
137 | - $values = $this->validateAndTrimHeader($name, $values); |
|
138 | - |
|
139 | - foreach ($values as $value) { |
|
140 | - $this->headers[$name][] = $value; |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
17 | + /** |
|
18 | + * RFC-2616, RFC-7230 - case-insensitive; HTTP2 pack convert all header to lowercase |
|
19 | + * |
|
20 | + * @var array - all header name will be convert to lowercase |
|
21 | + */ |
|
22 | + protected array $headers = []; |
|
23 | + protected string $protocol = '1.1'; |
|
24 | + protected ?StreamInterface $stream = null; |
|
25 | + |
|
26 | + public function getProtocolVersion(): string |
|
27 | + { |
|
28 | + return $this->protocol; |
|
29 | + } |
|
30 | + |
|
31 | + public function withProtocolVersion($version): self |
|
32 | + { |
|
33 | + if ($this->protocol !== $version) { |
|
34 | + $this->protocol = $version; |
|
35 | + } |
|
36 | + |
|
37 | + return $this; |
|
38 | + } |
|
39 | + |
|
40 | + public function getHeaders(): array |
|
41 | + { |
|
42 | + return $this->headers; |
|
43 | + } |
|
44 | + |
|
45 | + public function hasHeader($name): bool |
|
46 | + { |
|
47 | + $name = strtolower($name); |
|
48 | + $hasHeader = $this->headers[$name] ?? null; |
|
49 | + return $hasHeader !== null; |
|
50 | + } |
|
51 | + |
|
52 | + public function getHeader($name): array |
|
53 | + { |
|
54 | + $name = strtolower($name); |
|
55 | + return $this->headers[$name] ?? []; |
|
56 | + } |
|
57 | + |
|
58 | + public function getHeaderLine($name): string |
|
59 | + { |
|
60 | + return implode(', ', $this->getHeader($name)); |
|
61 | + } |
|
62 | + |
|
63 | + public function withHeader($name, $value): self |
|
64 | + { |
|
65 | + $name = strtolower($name); |
|
66 | + $this->headers[$name] = $this->validateAndTrimHeader($name, (array)$value); |
|
67 | + return $this; |
|
68 | + } |
|
69 | + |
|
70 | + public function withoutHeader($name): self |
|
71 | + { |
|
72 | + $name = strtolower($name); |
|
73 | + unset($this->headers[$name]); |
|
74 | + return $this; |
|
75 | + } |
|
76 | + |
|
77 | + public function getBody(): StreamInterface |
|
78 | + { |
|
79 | + if (!$this->stream) { |
|
80 | + $this->stream = Stream::create(''); |
|
81 | + } |
|
82 | + |
|
83 | + return $this->stream; |
|
84 | + } |
|
85 | + |
|
86 | + public function withBody(StreamInterface $body): self |
|
87 | + { |
|
88 | + $this->stream = $body; |
|
89 | + return $this; |
|
90 | + } |
|
91 | + |
|
92 | + public function reset(): static |
|
93 | + { |
|
94 | + $this->headers = []; |
|
95 | + if ($this->stream) { |
|
96 | + $this->stream->close(); |
|
97 | + $this->stream = null; |
|
98 | + } |
|
99 | + |
|
100 | + return $this; |
|
101 | + } |
|
102 | + |
|
103 | + protected function validateAndTrimHeader(string $name, array $values): array |
|
104 | + { |
|
105 | + if (preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@", $name) !== 1) { |
|
106 | + throw new InvalidArgumentException('Header name must be an RFC 7230 compatible string.'); |
|
107 | + } |
|
108 | + |
|
109 | + $returnValues = []; |
|
110 | + foreach ($values as $v) { |
|
111 | + if ((!is_numeric($v) && !is_string($v)) || 1 !== preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string)$v)) { |
|
112 | + throw new InvalidArgumentException('Header values must be RFC 7230 compatible strings.'); |
|
113 | + } |
|
114 | + |
|
115 | + $returnValues[] = trim((string)$v); |
|
116 | + } |
|
117 | + |
|
118 | + return $returnValues; |
|
119 | + } |
|
120 | + |
|
121 | + public function withAddedHeader($name, $value): self |
|
122 | + { |
|
123 | + $this->setHeaders([$name => $value]); |
|
124 | + return $this; |
|
125 | + } |
|
126 | + |
|
127 | + protected function setHeaders(array $headers): void |
|
128 | + { |
|
129 | + foreach ($headers as $name => $values) { |
|
130 | + $values = (array)$values; |
|
131 | + $name = strtolower((string)$name); |
|
132 | + |
|
133 | + if (!$this->hasHeader($name)) { |
|
134 | + $this->headers[$name] = []; |
|
135 | + } |
|
136 | + |
|
137 | + $values = $this->validateAndTrimHeader($name, $values); |
|
138 | + |
|
139 | + foreach ($values as $value) { |
|
140 | + $this->headers[$name][] = $value; |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | 144 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $target = $target ?: '/'; |
55 | 55 | |
56 | 56 | if ('' !== $this->uri->getQuery()) { |
57 | - $target .= '?' . $this->uri->getQuery(); |
|
57 | + $target .= '?'.$this->uri->getQuery(); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->requestTarget = $target; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | if (null !== ($port = $this->uri->getPort())) { |
112 | - $host .= ':' . $port; |
|
112 | + $host .= ':'.$port; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | $this->headers['host'] = [$host]; |
@@ -199,9 +199,9 @@ |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | if (-1 === fseek($this->stream, $offset, $whence)) { |
202 | - throw new RuntimeException('Unable to seek to stream position ' . |
|
203 | - $offset . |
|
204 | - ' with whence ' . |
|
202 | + throw new RuntimeException('Unable to seek to stream position '. |
|
203 | + $offset. |
|
204 | + ' with whence '. |
|
205 | 205 | \var_export($whence, true)); |
206 | 206 | } |
207 | 207 | } |
@@ -5,8 +5,8 @@ |
||
5 | 5 | |
6 | 6 | interface JsonResponseInterface extends ServerMessageInterface |
7 | 7 | { |
8 | - public function getData(): array; |
|
9 | - public function setData(array $data): static; |
|
10 | - public function reset(): static; |
|
8 | + public function getData(): array; |
|
9 | + public function setData(array $data): static; |
|
10 | + public function reset(): static; |
|
11 | 11 | |
12 | 12 | } |
13 | 13 | \ No newline at end of file |
@@ -42,7 +42,7 @@ |
||
42 | 42 | |
43 | 43 | public function withBody(StreamInterface $body): Message |
44 | 44 | { |
45 | - $this->data = json_decode((string)$body, true, 512, JSON_THROW_ON_ERROR); |
|
45 | + $this->data = json_decode((string) $body, true, 512, JSON_THROW_ON_ERROR); |
|
46 | 46 | $this->isSyncBody = true; |
47 | 47 | return parent::withBody($body); |
48 | 48 | } |
@@ -59,10 +59,10 @@ |
||
59 | 59 | $resource = @fopen($filename, $mode); |
60 | 60 | if (false === $resource) { |
61 | 61 | if ('' === $mode || false === in_array($mode[0], ['r', 'w', 'a', 'x', 'c'])) { |
62 | - throw new InvalidArgumentException('The mode ' . $mode . ' is invalid.'); |
|
62 | + throw new InvalidArgumentException('The mode '.$mode.' is invalid.'); |
|
63 | 63 | } |
64 | 64 | |
65 | - throw new RuntimeException('The file ' . $filename . ' cannot be opened.'); |
|
65 | + throw new RuntimeException('The file '.$filename.' cannot be opened.'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | return Stream::create($resource); |
@@ -27,7 +27,7 @@ |
||
27 | 27 | $body = null, |
28 | 28 | $version = '1.1' |
29 | 29 | ) { |
30 | - return new Response((int)$statusCode, $headers, $body, $version, $reasonPhrase); |
|
30 | + return new Response((int) $statusCode, $headers, $body, $version, $reasonPhrase); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function createStream($body = null) |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $this->query = isset($parts['query']) ? $this->filterQueryAndFragment($parts['query']) : ''; |
44 | 44 | $this->fragment = isset($parts['fragment']) ? $this->filterQueryAndFragment($parts['fragment']) : ''; |
45 | 45 | if (isset($parts['pass'])) { |
46 | - $this->userInfo .= ':' . $parts['pass']; |
|
46 | + $this->userInfo .= ':'.$parts['pass']; |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | } |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | |
67 | 67 | $authority = $this->host; |
68 | 68 | if ('' !== $this->userInfo) { |
69 | - $authority = $this->userInfo . '@' . $authority; |
|
69 | + $authority = $this->userInfo.'@'.$authority; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | if (null !== $this->port) { |
73 | - $authority .= ':' . $this->port; |
|
73 | + $authority .= ':'.$this->port; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | return $authority; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | { |
119 | 119 | $info = $user; |
120 | 120 | if (null !== $password && '' !== $password) { |
121 | - $info .= ':' . $password; |
|
121 | + $info .= ':'.$password; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | $this->userInfo = $info; |
@@ -177,24 +177,24 @@ discard block |
||
177 | 177 | ): string { |
178 | 178 | $uri = ''; |
179 | 179 | if ('' !== $scheme) { |
180 | - $uri .= $scheme . ':'; |
|
180 | + $uri .= $scheme.':'; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | if ('' !== $authority) { |
184 | - $uri .= '//' . $authority; |
|
184 | + $uri .= '//'.$authority; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | if ('' !== $path) { |
188 | 188 | if ('/' !== $path[0]) { |
189 | 189 | if ('' !== $authority) { |
190 | 190 | // If the path is rootless and an authority is present, the path MUST be prefixed by "/" |
191 | - $path = '/' . $path; |
|
191 | + $path = '/'.$path; |
|
192 | 192 | } |
193 | 193 | } elseif (isset($path[1]) && '/' === $path[1]) { |
194 | 194 | if ('' === $authority) { |
195 | 195 | // If the path is starting with more than one "/" and no authority is present, the |
196 | 196 | // starting slashes MUST be reduced to one. |
197 | - $path = '/' . \ltrim($path, '/'); |
|
197 | + $path = '/'.\ltrim($path, '/'); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -202,11 +202,11 @@ discard block |
||
202 | 202 | } |
203 | 203 | |
204 | 204 | if ('' !== $query) { |
205 | - $uri .= '?' . $query; |
|
205 | + $uri .= '?'.$query; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | if ('' !== $fragment) { |
209 | - $uri .= '#' . $fragment; |
|
209 | + $uri .= '#'.$fragment; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | return $uri; |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | throw new InvalidArgumentException('Path must be a string'); |
233 | 233 | } |
234 | 234 | |
235 | - return preg_replace_callback('/(?:[^' . |
|
236 | - self::CHAR_UNRESERVED . |
|
237 | - self::CHAR_SUB_DELIMS . |
|
235 | + return preg_replace_callback('/(?:[^'. |
|
236 | + self::CHAR_UNRESERVED. |
|
237 | + self::CHAR_SUB_DELIMS. |
|
238 | 238 | '%:@\/]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $path); |
239 | 239 | } |
240 | 240 | |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | throw new InvalidArgumentException('Query and fragment must be a string'); |
245 | 245 | } |
246 | 246 | |
247 | - return preg_replace_callback('/(?:[^' . |
|
248 | - self::CHAR_UNRESERVED . |
|
249 | - self::CHAR_SUB_DELIMS . |
|
247 | + return preg_replace_callback('/(?:[^'. |
|
248 | + self::CHAR_UNRESERVED. |
|
249 | + self::CHAR_SUB_DELIMS. |
|
250 | 250 | '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $str); |
251 | 251 | } |
252 | 252 |