|
2 | 2 |
|
3 | 3 | namespace Pavlusha311245\UnitPhpSdk\Config\Routes; |
4 | 4 |
|
| 5 | +use Pavlusha311245\UnitPhpSdk\Enums\HttpMethodsEnum; |
5 | 6 | use Pavlusha311245\UnitPhpSdk\Enums\HttpSchemeEnum; |
6 | 7 |
|
7 | 8 | class RouteMatch |
8 | 9 | { |
| 10 | + /** |
| 11 | + * Host header field, converted to lower case and normalized by removing the port number and the trailing period (if any). |
| 12 | + * |
| 13 | + * @var string |
| 14 | + */ |
9 | 15 | private string $_host; |
10 | 16 |
|
11 | | - private string|null $_method; |
| 17 | + /** |
| 18 | + * Method from the request line, uppercased. |
| 19 | + * |
| 20 | + * @var HttpMethodsEnum |
| 21 | + */ |
| 22 | + private HttpMethodsEnum $_method; |
| 23 | + |
| 24 | + private string $_source; |
| 25 | + |
| 26 | + /** |
| 27 | + * Target IP address and optional port of the request. |
| 28 | + * |
| 29 | + * @var string |
| 30 | + */ |
| 31 | + private string $_destination; |
| 32 | + |
| 33 | + /** |
| 34 | + * URI scheme. Accepts only two patterns, either http or https. |
| 35 | + * |
| 36 | + * @var HttpSchemeEnum |
| 37 | + */ |
| 38 | + private HttpSchemeEnum $_scheme; |
| 39 | + |
| 40 | + /** |
| 41 | + * Request target, percent decoded and normalized by removing the query string and |
| 42 | + * resolving relative references (“.” and “..”, “//”). |
| 43 | + * |
| 44 | + * @var array|string |
| 45 | + */ |
| 46 | + private array|string $_uri; |
12 | 47 |
|
13 | | - private string|null $_source; |
| 48 | + /** |
| 49 | + * Arguments supplied with the request’s query string; these names and value pairs are percent decoded, |
| 50 | + * with plus signs (+) replaced by spaces. |
| 51 | + * |
| 52 | + * @var array |
| 53 | + */ |
| 54 | + private array $_arguments; |
14 | 55 |
|
15 | | - private string|null $_destination; |
| 56 | + /** |
| 57 | + * Query string, percent decoded, with plus signs (+) replaced by spaces. |
| 58 | + * |
| 59 | + * @var array |
| 60 | + */ |
| 61 | + private array $_query; |
16 | 62 |
|
17 | | - private HttpSchemeEnum|null $_scheme; |
| 63 | + /** |
| 64 | + * Cookies supplied with the request. |
| 65 | + * |
| 66 | + * @var array |
| 67 | + */ |
| 68 | + private array $_cookies; |
18 | 69 |
|
19 | | - private array|string|null $_uri; |
| 70 | + /** |
| 71 | + * Header fields supplied with the request. |
| 72 | + * |
| 73 | + * @var array |
| 74 | + */ |
| 75 | + private array $_headers; |
20 | 76 |
|
21 | | - public function __construct($data) |
| 77 | + public function __construct($data = null) |
22 | 78 | { |
23 | | - $this->_uri = $data['uri'] ?? null; |
24 | | - $this->_scheme = $data['scheme'] ?? null; |
25 | | - $this->_method = $data['method'] ?? null; |
| 79 | + if (!empty($data)) { |
| 80 | + $this->parseFromArray($data); |
| 81 | + } |
26 | 82 | } |
27 | 83 |
|
28 | 84 | /** |
29 | 85 | * Get method |
30 | 86 | * |
31 | | - * @return string|null |
| 87 | + * @return HttpMethodsEnum |
32 | 88 | */ |
33 | | - public function getMethod(): ?string |
| 89 | + public function getMethod(): HttpMethodsEnum |
34 | 90 | { |
35 | 91 | return $this->_method; |
36 | 92 | } |
37 | 93 |
|
| 94 | + /** |
| 95 | + * @param HttpMethodsEnum $method |
| 96 | + */ |
| 97 | + public function setMethod(HttpMethodsEnum $method): void |
| 98 | + { |
| 99 | + $this->_method = $method; |
| 100 | + } |
| 101 | + |
38 | 102 | /** |
39 | 103 | * Get uri |
40 | 104 | * |
@@ -69,4 +133,169 @@ public function setScheme(string $scheme): void |
69 | 133 | default => null |
70 | 134 | }; |
71 | 135 | } |
| 136 | + |
| 137 | + /** |
| 138 | + * @return array |
| 139 | + */ |
| 140 | + public function getArguments(): array |
| 141 | + { |
| 142 | + return $this->_arguments; |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * @param array $arguments |
| 147 | + */ |
| 148 | + public function setArguments(array $arguments): void |
| 149 | + { |
| 150 | + $this->_arguments = $arguments; |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * @return array |
| 155 | + */ |
| 156 | + public function getCookies(): array |
| 157 | + { |
| 158 | + return $this->_cookies; |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * @param array $cookies |
| 163 | + */ |
| 164 | + public function setCookies(array $cookies): void |
| 165 | + { |
| 166 | + $this->_cookies = $cookies; |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * @return string |
| 171 | + */ |
| 172 | + public function getDestination(): string |
| 173 | + { |
| 174 | + return $this->_destination; |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * @param string $destination |
| 179 | + */ |
| 180 | + public function setDestination(string $destination): void |
| 181 | + { |
| 182 | + $this->_destination = $destination; |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * @return array |
| 187 | + */ |
| 188 | + public function getHeaders(): array |
| 189 | + { |
| 190 | + return $this->_headers; |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * @param array $headers |
| 195 | + */ |
| 196 | + public function setHeaders(array $headers): void |
| 197 | + { |
| 198 | + $this->_headers = $headers; |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * @return string |
| 203 | + */ |
| 204 | + public function getHost(): string |
| 205 | + { |
| 206 | + return $this->_host; |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * @param string $host |
| 211 | + */ |
| 212 | + public function setHost(string $host): void |
| 213 | + { |
| 214 | + $this->_host = $host; |
| 215 | + } |
| 216 | + |
| 217 | + /** |
| 218 | + * @return array |
| 219 | + */ |
| 220 | + public function getQuery(): array |
| 221 | + { |
| 222 | + return $this->_query; |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * @param array $query |
| 227 | + */ |
| 228 | + public function setQuery(array $query): void |
| 229 | + { |
| 230 | + $this->_query = $query; |
| 231 | + } |
| 232 | + |
| 233 | + |
| 234 | + /** |
| 235 | + * @return string |
| 236 | + */ |
| 237 | + public function getSource(): string |
| 238 | + { |
| 239 | + return $this->_source; |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * @param string $source |
| 244 | + */ |
| 245 | + public function setSource(string $source): void |
| 246 | + { |
| 247 | + $this->_source = $source; |
| 248 | + } |
| 249 | + |
| 250 | + |
| 251 | + /** |
| 252 | + * @param array|string $uri |
| 253 | + */ |
| 254 | + public function setUri(array|string $uri): void |
| 255 | + { |
| 256 | + $this->_uri = $uri; |
| 257 | + } |
| 258 | + |
| 259 | + public function parseFromArray(array $data): void |
| 260 | + { |
| 261 | + if (array_key_exists('arguments', $data)) { |
| 262 | + $this->setArguments($data['arguments']); |
| 263 | + } |
| 264 | + |
| 265 | + if (array_key_exists('cookies', $data)) { |
| 266 | + $this->setCookies($data['cookies']); |
| 267 | + } |
| 268 | + |
| 269 | + if (array_key_exists('destination', $data)) { |
| 270 | + $this->setDestination($data['destination']); |
| 271 | + } |
| 272 | + |
| 273 | + if (array_key_exists('headers', $data)) { |
| 274 | + $this->setHeaders($data['headers']); |
| 275 | + } |
| 276 | + |
| 277 | + if (array_key_exists('host', $data)) { |
| 278 | + $this->setHost($data['host']); |
| 279 | + } |
| 280 | + |
| 281 | + if (array_key_exists('method', $data)) { |
| 282 | + $this->setMethod(HttpMethodsEnum::from(strtoupper($data['method']))); |
| 283 | + } |
| 284 | + |
| 285 | + if (array_key_exists('query', $data)) { |
| 286 | + $this->setQuery($data['query']); |
| 287 | + } |
| 288 | + |
| 289 | + if (array_key_exists('scheme', $data)) { |
| 290 | + $this->setScheme(HttpSchemeEnum::from($data['scheme'])->value); |
| 291 | + } |
| 292 | + |
| 293 | + if (array_key_exists('source', $data)) { |
| 294 | + $this->setSource($data['source']); |
| 295 | + } |
| 296 | + |
| 297 | + if (array_key_exists('uri', $data)) { |
| 298 | + $this->setUri($data['uri']); |
| 299 | + } |
| 300 | + } |
72 | 301 | } |
0 commit comments