@@ -26,96 +26,96 @@ |
||
26 | 26 | class Response extends Message implements ResponseInterface |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Status code of the message |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - protected $statusCode = 200; |
|
35 | - |
|
36 | - /** |
|
37 | - * Reason phrase of the message |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $reasonPhrase = 'OK'; |
|
42 | - |
|
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - */ |
|
46 | - public function getStatusCode() : int |
|
47 | - { |
|
48 | - return $this->statusCode; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * {@inheritDoc} |
|
53 | - */ |
|
54 | - public function getReasonPhrase() : string |
|
55 | - { |
|
56 | - return $this->reasonPhrase; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - */ |
|
62 | - public function withStatus($statusCode, $reasonPhrase = '') : ResponseInterface |
|
63 | - { |
|
64 | - $this->validateStatusCode($statusCode); |
|
65 | - $this->validateReasonPhrase($reasonPhrase); |
|
66 | - |
|
67 | - if ('' === $reasonPhrase) { |
|
68 | - $reasonPhrase = PHRASES[$statusCode] ?? 'Unknown Status Code'; |
|
69 | - } |
|
70 | - |
|
71 | - $clone = clone $this; |
|
72 | - $clone->statusCode = $statusCode; |
|
73 | - $clone->reasonPhrase = $reasonPhrase; |
|
74 | - |
|
75 | - return $clone; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Validates the given status-code |
|
80 | - * |
|
81 | - * @param mixed $statusCode |
|
82 | - * |
|
83 | - * @return void |
|
84 | - * |
|
85 | - * @throws \InvalidArgumentException |
|
86 | - * |
|
87 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
88 | - */ |
|
89 | - protected function validateStatusCode($statusCode) : void |
|
90 | - { |
|
91 | - if (! \is_int($statusCode)) { |
|
92 | - throw new \InvalidArgumentException('HTTP status-code must be an integer'); |
|
93 | - } |
|
94 | - |
|
95 | - if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
96 | - throw new \InvalidArgumentException(\sprintf('The given status-code "%d" is not valid', $statusCode)); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Validates the given reason-phrase |
|
102 | - * |
|
103 | - * @param mixed $reasonPhrase |
|
104 | - * |
|
105 | - * @return void |
|
106 | - * |
|
107 | - * @throws \InvalidArgumentException |
|
108 | - * |
|
109 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
110 | - */ |
|
111 | - protected function validateReasonPhrase($reasonPhrase) : void |
|
112 | - { |
|
113 | - if (! \is_string($reasonPhrase)) { |
|
114 | - throw new \InvalidArgumentException('HTTP reason-phrase must be a string'); |
|
115 | - } |
|
116 | - |
|
117 | - if (! \preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $reasonPhrase)) { |
|
118 | - throw new \InvalidArgumentException(\sprintf('The given reason-phrase "%s" is not valid', $reasonPhrase)); |
|
119 | - } |
|
120 | - } |
|
29 | + /** |
|
30 | + * Status code of the message |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + protected $statusCode = 200; |
|
35 | + |
|
36 | + /** |
|
37 | + * Reason phrase of the message |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $reasonPhrase = 'OK'; |
|
42 | + |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + */ |
|
46 | + public function getStatusCode() : int |
|
47 | + { |
|
48 | + return $this->statusCode; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * {@inheritDoc} |
|
53 | + */ |
|
54 | + public function getReasonPhrase() : string |
|
55 | + { |
|
56 | + return $this->reasonPhrase; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + */ |
|
62 | + public function withStatus($statusCode, $reasonPhrase = '') : ResponseInterface |
|
63 | + { |
|
64 | + $this->validateStatusCode($statusCode); |
|
65 | + $this->validateReasonPhrase($reasonPhrase); |
|
66 | + |
|
67 | + if ('' === $reasonPhrase) { |
|
68 | + $reasonPhrase = PHRASES[$statusCode] ?? 'Unknown Status Code'; |
|
69 | + } |
|
70 | + |
|
71 | + $clone = clone $this; |
|
72 | + $clone->statusCode = $statusCode; |
|
73 | + $clone->reasonPhrase = $reasonPhrase; |
|
74 | + |
|
75 | + return $clone; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Validates the given status-code |
|
80 | + * |
|
81 | + * @param mixed $statusCode |
|
82 | + * |
|
83 | + * @return void |
|
84 | + * |
|
85 | + * @throws \InvalidArgumentException |
|
86 | + * |
|
87 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
88 | + */ |
|
89 | + protected function validateStatusCode($statusCode) : void |
|
90 | + { |
|
91 | + if (! \is_int($statusCode)) { |
|
92 | + throw new \InvalidArgumentException('HTTP status-code must be an integer'); |
|
93 | + } |
|
94 | + |
|
95 | + if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
96 | + throw new \InvalidArgumentException(\sprintf('The given status-code "%d" is not valid', $statusCode)); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Validates the given reason-phrase |
|
102 | + * |
|
103 | + * @param mixed $reasonPhrase |
|
104 | + * |
|
105 | + * @return void |
|
106 | + * |
|
107 | + * @throws \InvalidArgumentException |
|
108 | + * |
|
109 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.2 |
|
110 | + */ |
|
111 | + protected function validateReasonPhrase($reasonPhrase) : void |
|
112 | + { |
|
113 | + if (! \is_string($reasonPhrase)) { |
|
114 | + throw new \InvalidArgumentException('HTTP reason-phrase must be a string'); |
|
115 | + } |
|
116 | + |
|
117 | + if (! \preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $reasonPhrase)) { |
|
118 | + throw new \InvalidArgumentException(\sprintf('The given reason-phrase "%s" is not valid', $reasonPhrase)); |
|
119 | + } |
|
120 | + } |
|
121 | 121 | } |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function validateStatusCode($statusCode) : void |
90 | 90 | { |
91 | - if (! \is_int($statusCode)) { |
|
91 | + if (!\is_int($statusCode)) { |
|
92 | 92 | throw new \InvalidArgumentException('HTTP status-code must be an integer'); |
93 | 93 | } |
94 | 94 | |
95 | - if (! ($statusCode >= 100 && $statusCode <= 599)) { |
|
95 | + if (!($statusCode >= 100 && $statusCode <= 599)) { |
|
96 | 96 | throw new \InvalidArgumentException(\sprintf('The given status-code "%d" is not valid', $statusCode)); |
97 | 97 | } |
98 | 98 | } |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function validateReasonPhrase($reasonPhrase) : void |
112 | 112 | { |
113 | - if (! \is_string($reasonPhrase)) { |
|
113 | + if (!\is_string($reasonPhrase)) { |
|
114 | 114 | throw new \InvalidArgumentException('HTTP reason-phrase must be a string'); |
115 | 115 | } |
116 | 116 | |
117 | - if (! \preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $reasonPhrase)) { |
|
117 | + if (!\preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $reasonPhrase)) { |
|
118 | 118 | throw new \InvalidArgumentException(\sprintf('The given reason-phrase "%s" is not valid', $reasonPhrase)); |
119 | 119 | } |
120 | 120 | } |
@@ -27,161 +27,161 @@ |
||
27 | 27 | class Request extends Message implements RequestInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Method of the message |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $method = 'GET'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Request target of the message |
|
39 | - * |
|
40 | - * @var null|string |
|
41 | - */ |
|
42 | - protected $requestTarget; |
|
43 | - |
|
44 | - /** |
|
45 | - * URI of the message |
|
46 | - * |
|
47 | - * @var null|UriInterface |
|
48 | - */ |
|
49 | - protected $uri; |
|
50 | - |
|
51 | - /** |
|
52 | - * {@inheritDoc} |
|
53 | - */ |
|
54 | - public function getMethod() : string |
|
55 | - { |
|
56 | - return $this->method; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - */ |
|
62 | - public function withMethod($method) : RequestInterface |
|
63 | - { |
|
64 | - $this->validateMethod($method); |
|
65 | - |
|
66 | - $clone = clone $this; |
|
67 | - $clone->method = \strtoupper($method); |
|
68 | - |
|
69 | - return $clone; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * {@inheritDoc} |
|
74 | - */ |
|
75 | - public function getRequestTarget() : string |
|
76 | - { |
|
77 | - if (! (null === $this->requestTarget)) { |
|
78 | - return $this->requestTarget; |
|
79 | - } |
|
80 | - |
|
81 | - if (! ($this->uri instanceof UriInterface)) { |
|
82 | - return '/'; |
|
83 | - } |
|
84 | - |
|
85 | - // https://tools.ietf.org/html/rfc7230#section-5.3.1 |
|
86 | - // https://tools.ietf.org/html/rfc7230#section-2.7 |
|
87 | - // |
|
88 | - // origin-form = absolute-path [ "?" query ] |
|
89 | - // absolute-path = 1*( "/" segment ) |
|
90 | - if (! (0 === \strncmp($this->uri->getPath(), '/', 1))) { |
|
91 | - return '/'; |
|
92 | - } |
|
93 | - |
|
94 | - $origin = $this->uri->getPath(); |
|
95 | - if (! ('' === $this->uri->getQuery())) { |
|
96 | - $origin .= '?' . $this->uri->getQuery(); |
|
97 | - } |
|
98 | - |
|
99 | - return $origin; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * {@inheritDoc} |
|
104 | - */ |
|
105 | - public function withRequestTarget($requestTarget) : RequestInterface |
|
106 | - { |
|
107 | - $this->validateRequestTarget($requestTarget); |
|
108 | - |
|
109 | - $clone = clone $this; |
|
110 | - $clone->requestTarget = $requestTarget; |
|
111 | - |
|
112 | - return $clone; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * {@inheritDoc} |
|
117 | - */ |
|
118 | - public function getUri() : ?UriInterface |
|
119 | - { |
|
120 | - return $this->uri; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * {@inheritDoc} |
|
125 | - */ |
|
126 | - public function withUri(UriInterface $uri, $preserveHost = false) : RequestInterface |
|
127 | - { |
|
128 | - $clone = clone $this; |
|
129 | - $clone->uri = $uri; |
|
130 | - |
|
131 | - if ('' === $uri->getHost() || ($preserveHost && $clone->hasHeader('host'))) { |
|
132 | - return $clone; |
|
133 | - } |
|
134 | - |
|
135 | - $newhost = $uri->getHost(); |
|
136 | - if (! (null === $uri->getPort())) { |
|
137 | - $newhost .= ':' . $uri->getPort(); |
|
138 | - } |
|
139 | - |
|
140 | - // Reassigning the "Host" header |
|
141 | - return $clone->withHeader('host', $newhost); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Validates the given method |
|
146 | - * |
|
147 | - * @param mixed $method |
|
148 | - * |
|
149 | - * @return void |
|
150 | - * |
|
151 | - * @throws \InvalidArgumentException |
|
152 | - * |
|
153 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.1 |
|
154 | - */ |
|
155 | - protected function validateMethod($method) : void |
|
156 | - { |
|
157 | - if (! \is_string($method)) { |
|
158 | - throw new \InvalidArgumentException('HTTP method must be a string'); |
|
159 | - } |
|
160 | - |
|
161 | - if (! \preg_match(HeaderInterface::RFC7230_TOKEN, $method)) { |
|
162 | - throw new \InvalidArgumentException(\sprintf('The given method "%s" is not valid', $method)); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Validates the given request-target |
|
168 | - * |
|
169 | - * @param mixed $requestTarget |
|
170 | - * |
|
171 | - * @return void |
|
172 | - * |
|
173 | - * @throws \InvalidArgumentException |
|
174 | - * |
|
175 | - * @link https://tools.ietf.org/html/rfc7230#section-5.3 |
|
176 | - */ |
|
177 | - protected function validateRequestTarget($requestTarget) : void |
|
178 | - { |
|
179 | - if (! \is_string($requestTarget)) { |
|
180 | - throw new \InvalidArgumentException('HTTP request-target must be a string'); |
|
181 | - } |
|
182 | - |
|
183 | - if (! \preg_match('/^[\x21-\x7E\x80-\xFF]+$/', $requestTarget)) { |
|
184 | - throw new \InvalidArgumentException(\sprintf('The given request-target "%s" is not valid', $requestTarget)); |
|
185 | - } |
|
186 | - } |
|
30 | + /** |
|
31 | + * Method of the message |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $method = 'GET'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Request target of the message |
|
39 | + * |
|
40 | + * @var null|string |
|
41 | + */ |
|
42 | + protected $requestTarget; |
|
43 | + |
|
44 | + /** |
|
45 | + * URI of the message |
|
46 | + * |
|
47 | + * @var null|UriInterface |
|
48 | + */ |
|
49 | + protected $uri; |
|
50 | + |
|
51 | + /** |
|
52 | + * {@inheritDoc} |
|
53 | + */ |
|
54 | + public function getMethod() : string |
|
55 | + { |
|
56 | + return $this->method; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + */ |
|
62 | + public function withMethod($method) : RequestInterface |
|
63 | + { |
|
64 | + $this->validateMethod($method); |
|
65 | + |
|
66 | + $clone = clone $this; |
|
67 | + $clone->method = \strtoupper($method); |
|
68 | + |
|
69 | + return $clone; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * {@inheritDoc} |
|
74 | + */ |
|
75 | + public function getRequestTarget() : string |
|
76 | + { |
|
77 | + if (! (null === $this->requestTarget)) { |
|
78 | + return $this->requestTarget; |
|
79 | + } |
|
80 | + |
|
81 | + if (! ($this->uri instanceof UriInterface)) { |
|
82 | + return '/'; |
|
83 | + } |
|
84 | + |
|
85 | + // https://tools.ietf.org/html/rfc7230#section-5.3.1 |
|
86 | + // https://tools.ietf.org/html/rfc7230#section-2.7 |
|
87 | + // |
|
88 | + // origin-form = absolute-path [ "?" query ] |
|
89 | + // absolute-path = 1*( "/" segment ) |
|
90 | + if (! (0 === \strncmp($this->uri->getPath(), '/', 1))) { |
|
91 | + return '/'; |
|
92 | + } |
|
93 | + |
|
94 | + $origin = $this->uri->getPath(); |
|
95 | + if (! ('' === $this->uri->getQuery())) { |
|
96 | + $origin .= '?' . $this->uri->getQuery(); |
|
97 | + } |
|
98 | + |
|
99 | + return $origin; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * {@inheritDoc} |
|
104 | + */ |
|
105 | + public function withRequestTarget($requestTarget) : RequestInterface |
|
106 | + { |
|
107 | + $this->validateRequestTarget($requestTarget); |
|
108 | + |
|
109 | + $clone = clone $this; |
|
110 | + $clone->requestTarget = $requestTarget; |
|
111 | + |
|
112 | + return $clone; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * {@inheritDoc} |
|
117 | + */ |
|
118 | + public function getUri() : ?UriInterface |
|
119 | + { |
|
120 | + return $this->uri; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * {@inheritDoc} |
|
125 | + */ |
|
126 | + public function withUri(UriInterface $uri, $preserveHost = false) : RequestInterface |
|
127 | + { |
|
128 | + $clone = clone $this; |
|
129 | + $clone->uri = $uri; |
|
130 | + |
|
131 | + if ('' === $uri->getHost() || ($preserveHost && $clone->hasHeader('host'))) { |
|
132 | + return $clone; |
|
133 | + } |
|
134 | + |
|
135 | + $newhost = $uri->getHost(); |
|
136 | + if (! (null === $uri->getPort())) { |
|
137 | + $newhost .= ':' . $uri->getPort(); |
|
138 | + } |
|
139 | + |
|
140 | + // Reassigning the "Host" header |
|
141 | + return $clone->withHeader('host', $newhost); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Validates the given method |
|
146 | + * |
|
147 | + * @param mixed $method |
|
148 | + * |
|
149 | + * @return void |
|
150 | + * |
|
151 | + * @throws \InvalidArgumentException |
|
152 | + * |
|
153 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.1 |
|
154 | + */ |
|
155 | + protected function validateMethod($method) : void |
|
156 | + { |
|
157 | + if (! \is_string($method)) { |
|
158 | + throw new \InvalidArgumentException('HTTP method must be a string'); |
|
159 | + } |
|
160 | + |
|
161 | + if (! \preg_match(HeaderInterface::RFC7230_TOKEN, $method)) { |
|
162 | + throw new \InvalidArgumentException(\sprintf('The given method "%s" is not valid', $method)); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Validates the given request-target |
|
168 | + * |
|
169 | + * @param mixed $requestTarget |
|
170 | + * |
|
171 | + * @return void |
|
172 | + * |
|
173 | + * @throws \InvalidArgumentException |
|
174 | + * |
|
175 | + * @link https://tools.ietf.org/html/rfc7230#section-5.3 |
|
176 | + */ |
|
177 | + protected function validateRequestTarget($requestTarget) : void |
|
178 | + { |
|
179 | + if (! \is_string($requestTarget)) { |
|
180 | + throw new \InvalidArgumentException('HTTP request-target must be a string'); |
|
181 | + } |
|
182 | + |
|
183 | + if (! \preg_match('/^[\x21-\x7E\x80-\xFF]+$/', $requestTarget)) { |
|
184 | + throw new \InvalidArgumentException(\sprintf('The given request-target "%s" is not valid', $requestTarget)); |
|
185 | + } |
|
186 | + } |
|
187 | 187 | } |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function getRequestTarget() : string |
76 | 76 | { |
77 | - if (! (null === $this->requestTarget)) { |
|
77 | + if (!(null === $this->requestTarget)) { |
|
78 | 78 | return $this->requestTarget; |
79 | 79 | } |
80 | 80 | |
81 | - if (! ($this->uri instanceof UriInterface)) { |
|
81 | + if (!($this->uri instanceof UriInterface)) { |
|
82 | 82 | return '/'; |
83 | 83 | } |
84 | 84 | |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | // |
88 | 88 | // origin-form = absolute-path [ "?" query ] |
89 | 89 | // absolute-path = 1*( "/" segment ) |
90 | - if (! (0 === \strncmp($this->uri->getPath(), '/', 1))) { |
|
90 | + if (!(0 === \strncmp($this->uri->getPath(), '/', 1))) { |
|
91 | 91 | return '/'; |
92 | 92 | } |
93 | 93 | |
94 | 94 | $origin = $this->uri->getPath(); |
95 | - if (! ('' === $this->uri->getQuery())) { |
|
95 | + if (!('' === $this->uri->getQuery())) { |
|
96 | 96 | $origin .= '?' . $this->uri->getQuery(); |
97 | 97 | } |
98 | 98 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | $newhost = $uri->getHost(); |
136 | - if (! (null === $uri->getPort())) { |
|
136 | + if (!(null === $uri->getPort())) { |
|
137 | 137 | $newhost .= ':' . $uri->getPort(); |
138 | 138 | } |
139 | 139 | |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | */ |
155 | 155 | protected function validateMethod($method) : void |
156 | 156 | { |
157 | - if (! \is_string($method)) { |
|
157 | + if (!\is_string($method)) { |
|
158 | 158 | throw new \InvalidArgumentException('HTTP method must be a string'); |
159 | 159 | } |
160 | 160 | |
161 | - if (! \preg_match(HeaderInterface::RFC7230_TOKEN, $method)) { |
|
161 | + if (!\preg_match(HeaderInterface::RFC7230_TOKEN, $method)) { |
|
162 | 162 | throw new \InvalidArgumentException(\sprintf('The given method "%s" is not valid', $method)); |
163 | 163 | } |
164 | 164 | } |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected function validateRequestTarget($requestTarget) : void |
178 | 178 | { |
179 | - if (! \is_string($requestTarget)) { |
|
179 | + if (!\is_string($requestTarget)) { |
|
180 | 180 | throw new \InvalidArgumentException('HTTP request-target must be a string'); |
181 | 181 | } |
182 | 182 | |
183 | - if (! \preg_match('/^[\x21-\x7E\x80-\xFF]+$/', $requestTarget)) { |
|
183 | + if (!\preg_match('/^[\x21-\x7E\x80-\xFF]+$/', $requestTarget)) { |
|
184 | 184 | throw new \InvalidArgumentException(\sprintf('The given request-target "%s" is not valid', $requestTarget)); |
185 | 185 | } |
186 | 186 | } |
@@ -28,342 +28,342 @@ |
||
28 | 28 | class Message implements MessageInterface |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Protocol version for the message |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $protocolVersion = '1.1'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Headers of the message |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $headers = []; |
|
44 | - |
|
45 | - /** |
|
46 | - * Body of the message |
|
47 | - * |
|
48 | - * @var null|StreamInterface |
|
49 | - */ |
|
50 | - protected $body; |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - */ |
|
55 | - public function getProtocolVersion() : string |
|
56 | - { |
|
57 | - return $this->protocolVersion; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - */ |
|
63 | - public function withProtocolVersion($protocolVersion) : MessageInterface |
|
64 | - { |
|
65 | - $this->validateProtocolVersion($protocolVersion); |
|
66 | - |
|
67 | - $clone = clone $this; |
|
68 | - $clone->protocolVersion = $protocolVersion; |
|
69 | - |
|
70 | - return $clone; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * {@inheritDoc} |
|
75 | - */ |
|
76 | - public function getHeaders() : array |
|
77 | - { |
|
78 | - return $this->headers; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * {@inheritDoc} |
|
83 | - */ |
|
84 | - public function hasHeader($name) : bool |
|
85 | - { |
|
86 | - $name = $this->normalizeHeaderName($name); |
|
87 | - |
|
88 | - return ! empty($this->headers[$name]); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * {@inheritDoc} |
|
93 | - */ |
|
94 | - public function getHeader($name) : array |
|
95 | - { |
|
96 | - $name = $this->normalizeHeaderName($name); |
|
97 | - if (empty($this->headers[$name])) { |
|
98 | - return []; |
|
99 | - } |
|
100 | - |
|
101 | - return $this->headers[$name]; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * {@inheritDoc} |
|
106 | - */ |
|
107 | - public function getHeaderLine($name) : string |
|
108 | - { |
|
109 | - $name = $this->normalizeHeaderName($name); |
|
110 | - if (empty($this->headers[$name])) { |
|
111 | - return ''; |
|
112 | - } |
|
113 | - |
|
114 | - return \implode(', ', $this->headers[$name]); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * {@inheritDoc} |
|
119 | - */ |
|
120 | - public function withHeader($name, $value, bool $append = false) : MessageInterface |
|
121 | - { |
|
122 | - $this->validateHeaderName($name); |
|
123 | - $this->validateHeaderValue($value); |
|
124 | - |
|
125 | - $name = $this->normalizeHeaderName($name); |
|
126 | - $value = $this->normalizeHeaderValue($value); |
|
127 | - |
|
128 | - if (isset($this->headers[$name]) && $append) { |
|
129 | - $value = \array_merge($this->headers[$name], $value); |
|
130 | - } |
|
131 | - |
|
132 | - $clone = clone $this; |
|
133 | - $clone->headers[$name] = $value; |
|
134 | - |
|
135 | - return $clone; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * {@inheritDoc} |
|
140 | - */ |
|
141 | - public function withAddedHeader($name, $value) : MessageInterface |
|
142 | - { |
|
143 | - return $this->withHeader($name, $value, true); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Returns a new instance with the given headers |
|
148 | - * |
|
149 | - * [!] This method is not associated with PSR-7. |
|
150 | - * |
|
151 | - * @param iterable $headers |
|
152 | - * @param bool $append |
|
153 | - * |
|
154 | - * @return MessageInterface |
|
155 | - * |
|
156 | - * @since 1.3.0 |
|
157 | - */ |
|
158 | - public function withMultipleHeaders(iterable $headers, bool $append = false) : MessageInterface |
|
159 | - { |
|
160 | - $result = clone $this; |
|
161 | - |
|
162 | - foreach ($headers as $name => $value) { |
|
163 | - $result = $result->withHeader($name, $value, $append); |
|
164 | - } |
|
165 | - |
|
166 | - return $result; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns a new instance with the given header |
|
171 | - * |
|
172 | - * [!] This method is not associated with PSR-7. |
|
173 | - * |
|
174 | - * @param HeaderInterface $header |
|
175 | - * @param bool $append |
|
176 | - * |
|
177 | - * @return MessageInterface |
|
178 | - * |
|
179 | - * @since 1.4.0 |
|
180 | - */ |
|
181 | - public function withHeaderObject(HeaderInterface $header, bool $append = false) : MessageInterface |
|
182 | - { |
|
183 | - $name = $header->getFieldName(); |
|
184 | - $value = $header->getFieldValue(); |
|
185 | - |
|
186 | - $result = clone $this; |
|
187 | - $result = $result->withHeader($name, $value, $append); |
|
188 | - |
|
189 | - return $result; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Returns a new instance with the given headers |
|
194 | - * |
|
195 | - * [!] This method is not associated with PSR-7. |
|
196 | - * |
|
197 | - * @param HeaderCollectionInterface $headers |
|
198 | - * @param bool $append |
|
199 | - * |
|
200 | - * @return MessageInterface |
|
201 | - * |
|
202 | - * @since 1.4.0 |
|
203 | - */ |
|
204 | - public function withHeaderCollection(HeaderCollectionInterface $headers, bool $append = false) : MessageInterface |
|
205 | - { |
|
206 | - $result = clone $this; |
|
207 | - |
|
208 | - foreach ($headers as $header) { |
|
209 | - $name = $header->getFieldName(); |
|
210 | - $value = $header->getFieldValue(); |
|
211 | - |
|
212 | - $result = $result->withHeader($name, $value, $append); |
|
213 | - } |
|
214 | - |
|
215 | - return $result; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * {@inheritDoc} |
|
220 | - */ |
|
221 | - public function withoutHeader($name) : MessageInterface |
|
222 | - { |
|
223 | - $name = $this->normalizeHeaderName($name); |
|
224 | - |
|
225 | - $clone = clone $this; |
|
226 | - |
|
227 | - unset($clone->headers[$name]); |
|
228 | - |
|
229 | - return $clone; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * {@inheritDoc} |
|
234 | - */ |
|
235 | - public function getBody() : ?StreamInterface |
|
236 | - { |
|
237 | - return $this->body; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * {@inheritDoc} |
|
242 | - */ |
|
243 | - public function withBody(StreamInterface $body) : MessageInterface |
|
244 | - { |
|
245 | - $clone = clone $this; |
|
246 | - $clone->body = $body; |
|
247 | - |
|
248 | - return $clone; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Validates the given protocol version |
|
253 | - * |
|
254 | - * @param mixed $protocolVersion |
|
255 | - * |
|
256 | - * @return void |
|
257 | - * |
|
258 | - * @throws \InvalidArgumentException |
|
259 | - * |
|
260 | - * @link https://tools.ietf.org/html/rfc7230#section-2.6 |
|
261 | - * @link https://tools.ietf.org/html/rfc7540 |
|
262 | - */ |
|
263 | - protected function validateProtocolVersion($protocolVersion) : void |
|
264 | - { |
|
265 | - if (! \is_string($protocolVersion)) { |
|
266 | - throw new \InvalidArgumentException('HTTP protocol version must be a string'); |
|
267 | - } |
|
268 | - |
|
269 | - if (! \preg_match('/^\d(?:\.\d)?$/', $protocolVersion)) { |
|
270 | - throw new \InvalidArgumentException( |
|
271 | - \sprintf('The given protocol version "%s" is not valid', $protocolVersion) |
|
272 | - ); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Validates the given header name |
|
278 | - * |
|
279 | - * @param mixed $headerName |
|
280 | - * |
|
281 | - * @return void |
|
282 | - * |
|
283 | - * @throws \InvalidArgumentException |
|
284 | - * |
|
285 | - * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
286 | - */ |
|
287 | - protected function validateHeaderName($headerName) : void |
|
288 | - { |
|
289 | - if (! \is_string($headerName)) { |
|
290 | - throw new \InvalidArgumentException('Header name must be a string'); |
|
291 | - } |
|
292 | - |
|
293 | - if (! \preg_match(HeaderInterface::RFC7230_TOKEN, $headerName)) { |
|
294 | - throw new \InvalidArgumentException( |
|
295 | - \sprintf('The given header name "%s" is not valid', $headerName) |
|
296 | - ); |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Validates the given header value |
|
302 | - * |
|
303 | - * @param mixed $headerValue |
|
304 | - * |
|
305 | - * @return void |
|
306 | - * |
|
307 | - * @throws \InvalidArgumentException |
|
308 | - * |
|
309 | - * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
310 | - */ |
|
311 | - protected function validateHeaderValue($headerValue) : void |
|
312 | - { |
|
313 | - if (\is_string($headerValue)) { |
|
314 | - $headerValue = [$headerValue]; |
|
315 | - } |
|
316 | - |
|
317 | - if (! \is_array($headerValue) || [] === $headerValue) { |
|
318 | - throw new \InvalidArgumentException( |
|
319 | - 'Header value must be a string or not an empty array' |
|
320 | - ); |
|
321 | - } |
|
322 | - |
|
323 | - foreach ($headerValue as $oneOf) { |
|
324 | - if (! \is_string($oneOf)) { |
|
325 | - throw new \InvalidArgumentException( |
|
326 | - 'Header value must be a string or an array containing only strings' |
|
327 | - ); |
|
328 | - } |
|
329 | - |
|
330 | - if (! \preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $oneOf)) { |
|
331 | - throw new \InvalidArgumentException( |
|
332 | - \sprintf('The given header value "%s" is not valid', $oneOf) |
|
333 | - ); |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Normalizes the given header name |
|
340 | - * |
|
341 | - * @param string $headerName |
|
342 | - * |
|
343 | - * @return string |
|
344 | - * |
|
345 | - * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
346 | - */ |
|
347 | - protected function normalizeHeaderName($headerName) : string |
|
348 | - { |
|
349 | - // Each header field consists of a case-insensitive field name... |
|
350 | - $headerName = \strtolower($headerName); |
|
351 | - |
|
352 | - return $headerName; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Normalizes the given header value |
|
357 | - * |
|
358 | - * @param string|array $headerValue |
|
359 | - * |
|
360 | - * @return array |
|
361 | - */ |
|
362 | - protected function normalizeHeaderValue($headerValue) : array |
|
363 | - { |
|
364 | - $headerValue = (array) $headerValue; |
|
365 | - $headerValue = \array_values($headerValue); |
|
366 | - |
|
367 | - return $headerValue; |
|
368 | - } |
|
31 | + /** |
|
32 | + * Protocol version for the message |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $protocolVersion = '1.1'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Headers of the message |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $headers = []; |
|
44 | + |
|
45 | + /** |
|
46 | + * Body of the message |
|
47 | + * |
|
48 | + * @var null|StreamInterface |
|
49 | + */ |
|
50 | + protected $body; |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + */ |
|
55 | + public function getProtocolVersion() : string |
|
56 | + { |
|
57 | + return $this->protocolVersion; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + */ |
|
63 | + public function withProtocolVersion($protocolVersion) : MessageInterface |
|
64 | + { |
|
65 | + $this->validateProtocolVersion($protocolVersion); |
|
66 | + |
|
67 | + $clone = clone $this; |
|
68 | + $clone->protocolVersion = $protocolVersion; |
|
69 | + |
|
70 | + return $clone; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * {@inheritDoc} |
|
75 | + */ |
|
76 | + public function getHeaders() : array |
|
77 | + { |
|
78 | + return $this->headers; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * {@inheritDoc} |
|
83 | + */ |
|
84 | + public function hasHeader($name) : bool |
|
85 | + { |
|
86 | + $name = $this->normalizeHeaderName($name); |
|
87 | + |
|
88 | + return ! empty($this->headers[$name]); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * {@inheritDoc} |
|
93 | + */ |
|
94 | + public function getHeader($name) : array |
|
95 | + { |
|
96 | + $name = $this->normalizeHeaderName($name); |
|
97 | + if (empty($this->headers[$name])) { |
|
98 | + return []; |
|
99 | + } |
|
100 | + |
|
101 | + return $this->headers[$name]; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * {@inheritDoc} |
|
106 | + */ |
|
107 | + public function getHeaderLine($name) : string |
|
108 | + { |
|
109 | + $name = $this->normalizeHeaderName($name); |
|
110 | + if (empty($this->headers[$name])) { |
|
111 | + return ''; |
|
112 | + } |
|
113 | + |
|
114 | + return \implode(', ', $this->headers[$name]); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * {@inheritDoc} |
|
119 | + */ |
|
120 | + public function withHeader($name, $value, bool $append = false) : MessageInterface |
|
121 | + { |
|
122 | + $this->validateHeaderName($name); |
|
123 | + $this->validateHeaderValue($value); |
|
124 | + |
|
125 | + $name = $this->normalizeHeaderName($name); |
|
126 | + $value = $this->normalizeHeaderValue($value); |
|
127 | + |
|
128 | + if (isset($this->headers[$name]) && $append) { |
|
129 | + $value = \array_merge($this->headers[$name], $value); |
|
130 | + } |
|
131 | + |
|
132 | + $clone = clone $this; |
|
133 | + $clone->headers[$name] = $value; |
|
134 | + |
|
135 | + return $clone; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * {@inheritDoc} |
|
140 | + */ |
|
141 | + public function withAddedHeader($name, $value) : MessageInterface |
|
142 | + { |
|
143 | + return $this->withHeader($name, $value, true); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Returns a new instance with the given headers |
|
148 | + * |
|
149 | + * [!] This method is not associated with PSR-7. |
|
150 | + * |
|
151 | + * @param iterable $headers |
|
152 | + * @param bool $append |
|
153 | + * |
|
154 | + * @return MessageInterface |
|
155 | + * |
|
156 | + * @since 1.3.0 |
|
157 | + */ |
|
158 | + public function withMultipleHeaders(iterable $headers, bool $append = false) : MessageInterface |
|
159 | + { |
|
160 | + $result = clone $this; |
|
161 | + |
|
162 | + foreach ($headers as $name => $value) { |
|
163 | + $result = $result->withHeader($name, $value, $append); |
|
164 | + } |
|
165 | + |
|
166 | + return $result; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns a new instance with the given header |
|
171 | + * |
|
172 | + * [!] This method is not associated with PSR-7. |
|
173 | + * |
|
174 | + * @param HeaderInterface $header |
|
175 | + * @param bool $append |
|
176 | + * |
|
177 | + * @return MessageInterface |
|
178 | + * |
|
179 | + * @since 1.4.0 |
|
180 | + */ |
|
181 | + public function withHeaderObject(HeaderInterface $header, bool $append = false) : MessageInterface |
|
182 | + { |
|
183 | + $name = $header->getFieldName(); |
|
184 | + $value = $header->getFieldValue(); |
|
185 | + |
|
186 | + $result = clone $this; |
|
187 | + $result = $result->withHeader($name, $value, $append); |
|
188 | + |
|
189 | + return $result; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Returns a new instance with the given headers |
|
194 | + * |
|
195 | + * [!] This method is not associated with PSR-7. |
|
196 | + * |
|
197 | + * @param HeaderCollectionInterface $headers |
|
198 | + * @param bool $append |
|
199 | + * |
|
200 | + * @return MessageInterface |
|
201 | + * |
|
202 | + * @since 1.4.0 |
|
203 | + */ |
|
204 | + public function withHeaderCollection(HeaderCollectionInterface $headers, bool $append = false) : MessageInterface |
|
205 | + { |
|
206 | + $result = clone $this; |
|
207 | + |
|
208 | + foreach ($headers as $header) { |
|
209 | + $name = $header->getFieldName(); |
|
210 | + $value = $header->getFieldValue(); |
|
211 | + |
|
212 | + $result = $result->withHeader($name, $value, $append); |
|
213 | + } |
|
214 | + |
|
215 | + return $result; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * {@inheritDoc} |
|
220 | + */ |
|
221 | + public function withoutHeader($name) : MessageInterface |
|
222 | + { |
|
223 | + $name = $this->normalizeHeaderName($name); |
|
224 | + |
|
225 | + $clone = clone $this; |
|
226 | + |
|
227 | + unset($clone->headers[$name]); |
|
228 | + |
|
229 | + return $clone; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * {@inheritDoc} |
|
234 | + */ |
|
235 | + public function getBody() : ?StreamInterface |
|
236 | + { |
|
237 | + return $this->body; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * {@inheritDoc} |
|
242 | + */ |
|
243 | + public function withBody(StreamInterface $body) : MessageInterface |
|
244 | + { |
|
245 | + $clone = clone $this; |
|
246 | + $clone->body = $body; |
|
247 | + |
|
248 | + return $clone; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Validates the given protocol version |
|
253 | + * |
|
254 | + * @param mixed $protocolVersion |
|
255 | + * |
|
256 | + * @return void |
|
257 | + * |
|
258 | + * @throws \InvalidArgumentException |
|
259 | + * |
|
260 | + * @link https://tools.ietf.org/html/rfc7230#section-2.6 |
|
261 | + * @link https://tools.ietf.org/html/rfc7540 |
|
262 | + */ |
|
263 | + protected function validateProtocolVersion($protocolVersion) : void |
|
264 | + { |
|
265 | + if (! \is_string($protocolVersion)) { |
|
266 | + throw new \InvalidArgumentException('HTTP protocol version must be a string'); |
|
267 | + } |
|
268 | + |
|
269 | + if (! \preg_match('/^\d(?:\.\d)?$/', $protocolVersion)) { |
|
270 | + throw new \InvalidArgumentException( |
|
271 | + \sprintf('The given protocol version "%s" is not valid', $protocolVersion) |
|
272 | + ); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Validates the given header name |
|
278 | + * |
|
279 | + * @param mixed $headerName |
|
280 | + * |
|
281 | + * @return void |
|
282 | + * |
|
283 | + * @throws \InvalidArgumentException |
|
284 | + * |
|
285 | + * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
286 | + */ |
|
287 | + protected function validateHeaderName($headerName) : void |
|
288 | + { |
|
289 | + if (! \is_string($headerName)) { |
|
290 | + throw new \InvalidArgumentException('Header name must be a string'); |
|
291 | + } |
|
292 | + |
|
293 | + if (! \preg_match(HeaderInterface::RFC7230_TOKEN, $headerName)) { |
|
294 | + throw new \InvalidArgumentException( |
|
295 | + \sprintf('The given header name "%s" is not valid', $headerName) |
|
296 | + ); |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Validates the given header value |
|
302 | + * |
|
303 | + * @param mixed $headerValue |
|
304 | + * |
|
305 | + * @return void |
|
306 | + * |
|
307 | + * @throws \InvalidArgumentException |
|
308 | + * |
|
309 | + * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
310 | + */ |
|
311 | + protected function validateHeaderValue($headerValue) : void |
|
312 | + { |
|
313 | + if (\is_string($headerValue)) { |
|
314 | + $headerValue = [$headerValue]; |
|
315 | + } |
|
316 | + |
|
317 | + if (! \is_array($headerValue) || [] === $headerValue) { |
|
318 | + throw new \InvalidArgumentException( |
|
319 | + 'Header value must be a string or not an empty array' |
|
320 | + ); |
|
321 | + } |
|
322 | + |
|
323 | + foreach ($headerValue as $oneOf) { |
|
324 | + if (! \is_string($oneOf)) { |
|
325 | + throw new \InvalidArgumentException( |
|
326 | + 'Header value must be a string or an array containing only strings' |
|
327 | + ); |
|
328 | + } |
|
329 | + |
|
330 | + if (! \preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $oneOf)) { |
|
331 | + throw new \InvalidArgumentException( |
|
332 | + \sprintf('The given header value "%s" is not valid', $oneOf) |
|
333 | + ); |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Normalizes the given header name |
|
340 | + * |
|
341 | + * @param string $headerName |
|
342 | + * |
|
343 | + * @return string |
|
344 | + * |
|
345 | + * @link https://tools.ietf.org/html/rfc7230#section-3.2 |
|
346 | + */ |
|
347 | + protected function normalizeHeaderName($headerName) : string |
|
348 | + { |
|
349 | + // Each header field consists of a case-insensitive field name... |
|
350 | + $headerName = \strtolower($headerName); |
|
351 | + |
|
352 | + return $headerName; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Normalizes the given header value |
|
357 | + * |
|
358 | + * @param string|array $headerValue |
|
359 | + * |
|
360 | + * @return array |
|
361 | + */ |
|
362 | + protected function normalizeHeaderValue($headerValue) : array |
|
363 | + { |
|
364 | + $headerValue = (array) $headerValue; |
|
365 | + $headerValue = \array_values($headerValue); |
|
366 | + |
|
367 | + return $headerValue; |
|
368 | + } |
|
369 | 369 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | $name = $this->normalizeHeaderName($name); |
87 | 87 | |
88 | - return ! empty($this->headers[$name]); |
|
88 | + return !empty($this->headers[$name]); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | */ |
263 | 263 | protected function validateProtocolVersion($protocolVersion) : void |
264 | 264 | { |
265 | - if (! \is_string($protocolVersion)) { |
|
265 | + if (!\is_string($protocolVersion)) { |
|
266 | 266 | throw new \InvalidArgumentException('HTTP protocol version must be a string'); |
267 | 267 | } |
268 | 268 | |
269 | - if (! \preg_match('/^\d(?:\.\d)?$/', $protocolVersion)) { |
|
269 | + if (!\preg_match('/^\d(?:\.\d)?$/', $protocolVersion)) { |
|
270 | 270 | throw new \InvalidArgumentException( |
271 | 271 | \sprintf('The given protocol version "%s" is not valid', $protocolVersion) |
272 | 272 | ); |
@@ -286,11 +286,11 @@ discard block |
||
286 | 286 | */ |
287 | 287 | protected function validateHeaderName($headerName) : void |
288 | 288 | { |
289 | - if (! \is_string($headerName)) { |
|
289 | + if (!\is_string($headerName)) { |
|
290 | 290 | throw new \InvalidArgumentException('Header name must be a string'); |
291 | 291 | } |
292 | 292 | |
293 | - if (! \preg_match(HeaderInterface::RFC7230_TOKEN, $headerName)) { |
|
293 | + if (!\preg_match(HeaderInterface::RFC7230_TOKEN, $headerName)) { |
|
294 | 294 | throw new \InvalidArgumentException( |
295 | 295 | \sprintf('The given header name "%s" is not valid', $headerName) |
296 | 296 | ); |
@@ -314,20 +314,20 @@ discard block |
||
314 | 314 | $headerValue = [$headerValue]; |
315 | 315 | } |
316 | 316 | |
317 | - if (! \is_array($headerValue) || [] === $headerValue) { |
|
317 | + if (!\is_array($headerValue) || [] === $headerValue) { |
|
318 | 318 | throw new \InvalidArgumentException( |
319 | 319 | 'Header value must be a string or not an empty array' |
320 | 320 | ); |
321 | 321 | } |
322 | 322 | |
323 | 323 | foreach ($headerValue as $oneOf) { |
324 | - if (! \is_string($oneOf)) { |
|
324 | + if (!\is_string($oneOf)) { |
|
325 | 325 | throw new \InvalidArgumentException( |
326 | 326 | 'Header value must be a string or an array containing only strings' |
327 | 327 | ); |
328 | 328 | } |
329 | 329 | |
330 | - if (! \preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $oneOf)) { |
|
330 | + if (!\preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $oneOf)) { |
|
331 | 331 | throw new \InvalidArgumentException( |
332 | 332 | \sprintf('The given header value "%s" is not valid', $oneOf) |
333 | 333 | ); |
@@ -28,20 +28,20 @@ |
||
28 | 28 | class RequestFactory implements RequestFactoryInterface |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritDoc} |
|
33 | - */ |
|
34 | - public function createRequest(string $method, $uri) : RequestInterface |
|
35 | - { |
|
36 | - if (! ($uri instanceof UriInterface)) { |
|
37 | - $uri = (new UriFactory)->createUri($uri); |
|
38 | - } |
|
31 | + /** |
|
32 | + * {@inheritDoc} |
|
33 | + */ |
|
34 | + public function createRequest(string $method, $uri) : RequestInterface |
|
35 | + { |
|
36 | + if (! ($uri instanceof UriInterface)) { |
|
37 | + $uri = (new UriFactory)->createUri($uri); |
|
38 | + } |
|
39 | 39 | |
40 | - $body = (new StreamFactory)->createStream(); |
|
40 | + $body = (new StreamFactory)->createStream(); |
|
41 | 41 | |
42 | - return (new Request) |
|
43 | - ->withMethod($method) |
|
44 | - ->withUri($uri) |
|
45 | - ->withBody($body); |
|
46 | - } |
|
42 | + return (new Request) |
|
43 | + ->withMethod($method) |
|
44 | + ->withUri($uri) |
|
45 | + ->withBody($body); |
|
46 | + } |
|
47 | 47 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | */ |
34 | 34 | public function createRequest(string $method, $uri) : RequestInterface |
35 | 35 | { |
36 | - if (! ($uri instanceof UriInterface)) { |
|
36 | + if (!($uri instanceof UriInterface)) { |
|
37 | 37 | $uri = (new UriFactory)->createUri($uri); |
38 | 38 | } |
39 | 39 |
@@ -33,19 +33,19 @@ |
||
33 | 33 | class JsonException extends RuntimeException |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @return void |
|
38 | - * |
|
39 | - * @throws self |
|
40 | - */ |
|
41 | - public static function assert() : void |
|
42 | - { |
|
43 | - $code = json_last_error(); |
|
44 | - |
|
45 | - if (JSON_ERROR_NONE === $code) { |
|
46 | - return; |
|
47 | - } |
|
48 | - |
|
49 | - throw new self(json_last_error_msg(), $code); |
|
50 | - } |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + * |
|
39 | + * @throws self |
|
40 | + */ |
|
41 | + public static function assert() : void |
|
42 | + { |
|
43 | + $code = json_last_error(); |
|
44 | + |
|
45 | + if (JSON_ERROR_NONE === $code) { |
|
46 | + return; |
|
47 | + } |
|
48 | + |
|
49 | + throw new self(json_last_error_msg(), $code); |
|
50 | + } |
|
51 | 51 | } |
@@ -31,66 +31,66 @@ |
||
31 | 31 | class ResponseFactory implements ResponseFactoryInterface |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritDoc} |
|
36 | - */ |
|
37 | - public function createResponse(int $code = 200, string $reasonPhrase = '') : ResponseInterface |
|
38 | - { |
|
39 | - $body = (new StreamFactory)->createStream(); |
|
34 | + /** |
|
35 | + * {@inheritDoc} |
|
36 | + */ |
|
37 | + public function createResponse(int $code = 200, string $reasonPhrase = '') : ResponseInterface |
|
38 | + { |
|
39 | + $body = (new StreamFactory)->createStream(); |
|
40 | 40 | |
41 | - return (new Response) |
|
42 | - ->withStatus($code, $reasonPhrase) |
|
43 | - ->withBody($body); |
|
44 | - } |
|
41 | + return (new Response) |
|
42 | + ->withStatus($code, $reasonPhrase) |
|
43 | + ->withBody($body); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Creates a HTML response instance |
|
48 | - * |
|
49 | - * @param int $status |
|
50 | - * @param mixed $content |
|
51 | - * |
|
52 | - * @return ResponseInterface |
|
53 | - */ |
|
54 | - public function createHtmlResponse(int $status, $content) : ResponseInterface |
|
55 | - { |
|
56 | - $content = (string) $content; |
|
46 | + /** |
|
47 | + * Creates a HTML response instance |
|
48 | + * |
|
49 | + * @param int $status |
|
50 | + * @param mixed $content |
|
51 | + * |
|
52 | + * @return ResponseInterface |
|
53 | + */ |
|
54 | + public function createHtmlResponse(int $status, $content) : ResponseInterface |
|
55 | + { |
|
56 | + $content = (string) $content; |
|
57 | 57 | |
58 | - $body = (new StreamFactory)->createStream(); |
|
59 | - $body->write($content); |
|
58 | + $body = (new StreamFactory)->createStream(); |
|
59 | + $body->write($content); |
|
60 | 60 | |
61 | - return (new Response) |
|
62 | - ->withStatus($status) |
|
63 | - ->withHeader('Content-Type', 'text/html; charset=utf-8') |
|
64 | - ->withBody($body); |
|
65 | - } |
|
61 | + return (new Response) |
|
62 | + ->withStatus($status) |
|
63 | + ->withHeader('Content-Type', 'text/html; charset=utf-8') |
|
64 | + ->withBody($body); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Creates a JSON response instance |
|
69 | - * |
|
70 | - * @param int $status |
|
71 | - * @param mixed $payload |
|
72 | - * @param int $options |
|
73 | - * @param int $depth |
|
74 | - * |
|
75 | - * @return ResponseInterface |
|
76 | - * |
|
77 | - * @throws Exception\JsonException |
|
78 | - */ |
|
79 | - public function createJsonResponse(int $status, $payload, int $options = 0, int $depth = 512) : ResponseInterface |
|
80 | - { |
|
81 | - // clears a previous error... |
|
82 | - json_encode(null); |
|
67 | + /** |
|
68 | + * Creates a JSON response instance |
|
69 | + * |
|
70 | + * @param int $status |
|
71 | + * @param mixed $payload |
|
72 | + * @param int $options |
|
73 | + * @param int $depth |
|
74 | + * |
|
75 | + * @return ResponseInterface |
|
76 | + * |
|
77 | + * @throws Exception\JsonException |
|
78 | + */ |
|
79 | + public function createJsonResponse(int $status, $payload, int $options = 0, int $depth = 512) : ResponseInterface |
|
80 | + { |
|
81 | + // clears a previous error... |
|
82 | + json_encode(null); |
|
83 | 83 | |
84 | - $content = json_encode($payload, $options, $depth); |
|
84 | + $content = json_encode($payload, $options, $depth); |
|
85 | 85 | |
86 | - Exception\JsonException::assert(); |
|
86 | + Exception\JsonException::assert(); |
|
87 | 87 | |
88 | - $body = (new StreamFactory)->createStream(); |
|
89 | - $body->write($content); |
|
88 | + $body = (new StreamFactory)->createStream(); |
|
89 | + $body->write($content); |
|
90 | 90 | |
91 | - return (new Response) |
|
92 | - ->withStatus($status) |
|
93 | - ->withHeader('Content-Type', 'application/json; charset=utf-8') |
|
94 | - ->withBody($body); |
|
95 | - } |
|
91 | + return (new Response) |
|
92 | + ->withStatus($status) |
|
93 | + ->withHeader('Content-Type', 'application/json; charset=utf-8') |
|
94 | + ->withBody($body); |
|
95 | + } |
|
96 | 96 | } |
@@ -20,76 +20,76 @@ |
||
20 | 20 | */ |
21 | 21 | const PHRASES = [ |
22 | 22 | |
23 | - // 1xx |
|
24 | - 100 => 'Continue', |
|
25 | - 101 => 'Switching Protocols', |
|
26 | - 102 => 'Processing', |
|
27 | - 103 => 'Early Hints', |
|
23 | + // 1xx |
|
24 | + 100 => 'Continue', |
|
25 | + 101 => 'Switching Protocols', |
|
26 | + 102 => 'Processing', |
|
27 | + 103 => 'Early Hints', |
|
28 | 28 | |
29 | - // 2xx |
|
30 | - 200 => 'OK', |
|
31 | - 201 => 'Created', |
|
32 | - 202 => 'Accepted', |
|
33 | - 203 => 'Non-Authoritative Information', |
|
34 | - 204 => 'No Content', |
|
35 | - 205 => 'Reset Content', |
|
36 | - 206 => 'Partial Content', |
|
37 | - 207 => 'Multi-Status', |
|
38 | - 208 => 'Already Reported', |
|
39 | - 226 => 'IM Used', |
|
29 | + // 2xx |
|
30 | + 200 => 'OK', |
|
31 | + 201 => 'Created', |
|
32 | + 202 => 'Accepted', |
|
33 | + 203 => 'Non-Authoritative Information', |
|
34 | + 204 => 'No Content', |
|
35 | + 205 => 'Reset Content', |
|
36 | + 206 => 'Partial Content', |
|
37 | + 207 => 'Multi-Status', |
|
38 | + 208 => 'Already Reported', |
|
39 | + 226 => 'IM Used', |
|
40 | 40 | |
41 | - // 3xx |
|
42 | - 300 => 'Multiple Choices', |
|
43 | - 301 => 'Moved Permanently', |
|
44 | - 302 => 'Found', |
|
45 | - 303 => 'See Other', |
|
46 | - 304 => 'Not Modified', |
|
47 | - 305 => 'Use Proxy', |
|
48 | - 306 => '(Unused)', |
|
49 | - 307 => 'Temporary Redirect', |
|
50 | - 308 => 'Permanent Redirect', |
|
41 | + // 3xx |
|
42 | + 300 => 'Multiple Choices', |
|
43 | + 301 => 'Moved Permanently', |
|
44 | + 302 => 'Found', |
|
45 | + 303 => 'See Other', |
|
46 | + 304 => 'Not Modified', |
|
47 | + 305 => 'Use Proxy', |
|
48 | + 306 => '(Unused)', |
|
49 | + 307 => 'Temporary Redirect', |
|
50 | + 308 => 'Permanent Redirect', |
|
51 | 51 | |
52 | - // 4xx |
|
53 | - 400 => 'Bad Request', |
|
54 | - 401 => 'Unauthorized', |
|
55 | - 402 => 'Payment Required', |
|
56 | - 403 => 'Forbidden', |
|
57 | - 404 => 'Not Found', |
|
58 | - 405 => 'Method Not Allowed', |
|
59 | - 406 => 'Not Acceptable', |
|
60 | - 407 => 'Proxy Authentication Required', |
|
61 | - 408 => 'Request Timeout', |
|
62 | - 409 => 'Conflict', |
|
63 | - 410 => 'Gone', |
|
64 | - 411 => 'Length Required', |
|
65 | - 412 => 'Precondition Failed', |
|
66 | - 413 => 'Payload Too Large', |
|
67 | - 414 => 'URI Too Long', |
|
68 | - 415 => 'Unsupported Media Type', |
|
69 | - 416 => 'Range Not Satisfiable', |
|
70 | - 417 => 'Expectation Failed', |
|
71 | - 418 => 'I\'m a teapot', |
|
72 | - 421 => 'Misdirected Request', |
|
73 | - 422 => 'Unprocessable Entity', |
|
74 | - 423 => 'Locked', |
|
75 | - 424 => 'Failed Dependency', |
|
76 | - 425 => 'Too Early', |
|
77 | - 426 => 'Upgrade Required', |
|
78 | - 428 => 'Precondition Required', |
|
79 | - 429 => 'Too Many Requests', |
|
80 | - 431 => 'Request Header Fields Too Large', |
|
81 | - 451 => 'Unavailable For Legal Reasons', |
|
52 | + // 4xx |
|
53 | + 400 => 'Bad Request', |
|
54 | + 401 => 'Unauthorized', |
|
55 | + 402 => 'Payment Required', |
|
56 | + 403 => 'Forbidden', |
|
57 | + 404 => 'Not Found', |
|
58 | + 405 => 'Method Not Allowed', |
|
59 | + 406 => 'Not Acceptable', |
|
60 | + 407 => 'Proxy Authentication Required', |
|
61 | + 408 => 'Request Timeout', |
|
62 | + 409 => 'Conflict', |
|
63 | + 410 => 'Gone', |
|
64 | + 411 => 'Length Required', |
|
65 | + 412 => 'Precondition Failed', |
|
66 | + 413 => 'Payload Too Large', |
|
67 | + 414 => 'URI Too Long', |
|
68 | + 415 => 'Unsupported Media Type', |
|
69 | + 416 => 'Range Not Satisfiable', |
|
70 | + 417 => 'Expectation Failed', |
|
71 | + 418 => 'I\'m a teapot', |
|
72 | + 421 => 'Misdirected Request', |
|
73 | + 422 => 'Unprocessable Entity', |
|
74 | + 423 => 'Locked', |
|
75 | + 424 => 'Failed Dependency', |
|
76 | + 425 => 'Too Early', |
|
77 | + 426 => 'Upgrade Required', |
|
78 | + 428 => 'Precondition Required', |
|
79 | + 429 => 'Too Many Requests', |
|
80 | + 431 => 'Request Header Fields Too Large', |
|
81 | + 451 => 'Unavailable For Legal Reasons', |
|
82 | 82 | |
83 | - // 5xx |
|
84 | - 500 => 'Internal Server Error', |
|
85 | - 501 => 'Not Implemented', |
|
86 | - 502 => 'Bad Gateway', |
|
87 | - 503 => 'Service Unavailable', |
|
88 | - 504 => 'Gateway Timeout', |
|
89 | - 505 => 'HTTP Version Not Supported', |
|
90 | - 506 => 'Variant Also Negotiates', |
|
91 | - 507 => 'Insufficient Storage', |
|
92 | - 508 => 'Loop Detected', |
|
93 | - 510 => 'Not Extended', |
|
94 | - 511 => 'Network Authentication Required', |
|
83 | + // 5xx |
|
84 | + 500 => 'Internal Server Error', |
|
85 | + 501 => 'Not Implemented', |
|
86 | + 502 => 'Bad Gateway', |
|
87 | + 503 => 'Service Unavailable', |
|
88 | + 504 => 'Gateway Timeout', |
|
89 | + 505 => 'HTTP Version Not Supported', |
|
90 | + 506 => 'Variant Also Negotiates', |
|
91 | + 507 => 'Insufficient Storage', |
|
92 | + 508 => 'Loop Detected', |
|
93 | + 510 => 'Not Extended', |
|
94 | + 511 => 'Network Authentication Required', |
|
95 | 95 | ]; |