@@ -24,51 +24,51 @@ |
||
| 24 | 24 | final class UserInfo implements ComponentInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * URI component "user" |
|
| 29 | - * |
|
| 30 | - * @var User |
|
| 31 | - */ |
|
| 32 | - private User $user; |
|
| 27 | + /** |
|
| 28 | + * URI component "user" |
|
| 29 | + * |
|
| 30 | + * @var User |
|
| 31 | + */ |
|
| 32 | + private User $user; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * URI component "password" |
|
| 36 | - * |
|
| 37 | - * @var Password|null |
|
| 38 | - */ |
|
| 39 | - private ?Password $password = null; |
|
| 34 | + /** |
|
| 35 | + * URI component "password" |
|
| 36 | + * |
|
| 37 | + * @var Password|null |
|
| 38 | + */ |
|
| 39 | + private ?Password $password = null; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor of the class |
|
| 43 | - * |
|
| 44 | - * @param mixed $user |
|
| 45 | - * @param mixed $password |
|
| 46 | - * |
|
| 47 | - * @throws InvalidArgumentException |
|
| 48 | - * If the user or password aren't valid. |
|
| 49 | - */ |
|
| 50 | - public function __construct($user, $password = null) |
|
| 51 | - { |
|
| 52 | - $this->user = User::create($user); |
|
| 41 | + /** |
|
| 42 | + * Constructor of the class |
|
| 43 | + * |
|
| 44 | + * @param mixed $user |
|
| 45 | + * @param mixed $password |
|
| 46 | + * |
|
| 47 | + * @throws InvalidArgumentException |
|
| 48 | + * If the user or password aren't valid. |
|
| 49 | + */ |
|
| 50 | + public function __construct($user, $password = null) |
|
| 51 | + { |
|
| 52 | + $this->user = User::create($user); |
|
| 53 | 53 | |
| 54 | - if (isset($password)) { |
|
| 55 | - $this->password = Password::create($password); |
|
| 56 | - } |
|
| 57 | - } |
|
| 54 | + if (isset($password)) { |
|
| 55 | + $this->password = Password::create($password); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * {@inheritdoc} |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function getValue(): string |
|
| 65 | - { |
|
| 66 | - $value = $this->user->getValue(); |
|
| 59 | + /** |
|
| 60 | + * {@inheritdoc} |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function getValue(): string |
|
| 65 | + { |
|
| 66 | + $value = $this->user->getValue(); |
|
| 67 | 67 | |
| 68 | - if (isset($this->password)) { |
|
| 69 | - $value .= ':' . $this->password->getValue(); |
|
| 70 | - } |
|
| 68 | + if (isset($this->password)) { |
|
| 69 | + $value .= ':' . $this->password->getValue(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $value; |
|
| 73 | - } |
|
| 72 | + return $value; |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -31,53 +31,53 @@ |
||
| 31 | 31 | final class Scheme implements ComponentInterface |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Regular expression used for the component validation |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private const VALIDATION_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\x2b\x2d\x2e]*)?$/'; |
|
| 34 | + /** |
|
| 35 | + * Regular expression used for the component validation |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private const VALIDATION_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\x2b\x2d\x2e]*)?$/'; |
|
| 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 InvalidArgumentException |
|
| 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 InvalidArgumentException |
|
| 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 InvalidArgumentException('URI component "scheme" must be a string'); |
|
| 64 | - } |
|
| 62 | + if (!is_string($value)) { |
|
| 63 | + throw new InvalidArgumentException('URI component "scheme" must be a string'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if (!preg_match(self::VALIDATION_REGEX, $value)) { |
|
| 67 | - throw new InvalidArgumentException('Invalid URI component "scheme"'); |
|
| 68 | - } |
|
| 66 | + if (!preg_match(self::VALIDATION_REGEX, $value)) { |
|
| 67 | + throw new InvalidArgumentException('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 | } |
@@ -29,48 +29,48 @@ |
||
| 29 | 29 | final class Port implements ComponentInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The component value |
|
| 34 | - * |
|
| 35 | - * @var int|null |
|
| 36 | - */ |
|
| 37 | - private ?int $value = null; |
|
| 32 | + /** |
|
| 33 | + * The component value |
|
| 34 | + * |
|
| 35 | + * @var int|null |
|
| 36 | + */ |
|
| 37 | + private ?int $value = null; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Constructor of the class |
|
| 41 | - * |
|
| 42 | - * @param mixed $value |
|
| 43 | - * |
|
| 44 | - * @throws InvalidArgumentException |
|
| 45 | - * If the component isn't valid. |
|
| 46 | - */ |
|
| 47 | - public function __construct($value) |
|
| 48 | - { |
|
| 49 | - $min = 1; |
|
| 50 | - $max = (2 ** 16) - 1; |
|
| 39 | + /** |
|
| 40 | + * Constructor of the class |
|
| 41 | + * |
|
| 42 | + * @param mixed $value |
|
| 43 | + * |
|
| 44 | + * @throws InvalidArgumentException |
|
| 45 | + * If the component isn't valid. |
|
| 46 | + */ |
|
| 47 | + public function __construct($value) |
|
| 48 | + { |
|
| 49 | + $min = 1; |
|
| 50 | + $max = (2 ** 16) - 1; |
|
| 51 | 51 | |
| 52 | - if ($value === null) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 52 | + if ($value === null) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - if (!is_int($value)) { |
|
| 57 | - throw new InvalidArgumentException('URI component "port" must be an integer'); |
|
| 58 | - } |
|
| 56 | + if (!is_int($value)) { |
|
| 57 | + throw new InvalidArgumentException('URI component "port" must be an integer'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if (!($value >= $min && $value <= $max)) { |
|
| 61 | - throw new InvalidArgumentException('Invalid URI component "port"'); |
|
| 62 | - } |
|
| 60 | + if (!($value >= $min && $value <= $max)) { |
|
| 61 | + throw new InvalidArgumentException('Invalid URI component "port"'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $this->value = $value; |
|
| 65 | - } |
|
| 64 | + $this->value = $value; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * {@inheritdoc} |
|
| 69 | - * |
|
| 70 | - * @return int|null |
|
| 71 | - */ |
|
| 72 | - public function getValue(): ?int |
|
| 73 | - { |
|
| 74 | - return $this->value; |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * {@inheritdoc} |
|
| 69 | + * |
|
| 70 | + * @return int|null |
|
| 71 | + */ |
|
| 72 | + public function getValue(): ?int |
|
| 73 | + { |
|
| 74 | + return $this->value; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -36,285 +36,285 @@ |
||
| 36 | 36 | class Request extends Message implements RequestInterface, RequestMethodInterface |
| 37 | 37 | { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Regular Expression used for a request target validation |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - private const RFC7230_REQUEST_TARGET_REGEX = '/^[\x21-\x7E\x80-\xFF]+$/'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * The request method (aka verb) |
|
| 48 | - * |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - private string $method = self::METHOD_GET; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * The request URI |
|
| 55 | - * |
|
| 56 | - * @var UriInterface |
|
| 57 | - */ |
|
| 58 | - private UriInterface $uri; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The request target |
|
| 62 | - * |
|
| 63 | - * @var string|null |
|
| 64 | - */ |
|
| 65 | - private ?string $requestTarget = null; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Constructor of the class |
|
| 69 | - * |
|
| 70 | - * @param string|null $method |
|
| 71 | - * @param mixed $uri |
|
| 72 | - * @param array<string, string|string[]>|null $headers |
|
| 73 | - * @param StreamInterface|null $body |
|
| 74 | - * |
|
| 75 | - * @throws InvalidArgumentException |
|
| 76 | - * If one of the arguments isn't valid. |
|
| 77 | - */ |
|
| 78 | - public function __construct( |
|
| 79 | - ?string $method = null, |
|
| 80 | - $uri = null, |
|
| 81 | - ?array $headers = null, |
|
| 82 | - ?StreamInterface $body = null |
|
| 83 | - ) { |
|
| 84 | - if (isset($method)) { |
|
| 85 | - $this->setMethod($method); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $this->setUri($uri ?? '/'); |
|
| 89 | - |
|
| 90 | - if (isset($headers)) { |
|
| 91 | - $this->setHeaders($headers); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if (isset($body)) { |
|
| 95 | - $this->setBody($body); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Gets the request method |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - public function getMethod(): string |
|
| 105 | - { |
|
| 106 | - return $this->method; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Creates a new instance of the request with the given method |
|
| 111 | - * |
|
| 112 | - * @param string $method |
|
| 113 | - * |
|
| 114 | - * @return static |
|
| 115 | - * |
|
| 116 | - * @throws InvalidArgumentException |
|
| 117 | - * If the method isn't valid. |
|
| 118 | - */ |
|
| 119 | - public function withMethod($method): RequestInterface |
|
| 120 | - { |
|
| 121 | - $clone = clone $this; |
|
| 122 | - $clone->setMethod($method); |
|
| 123 | - |
|
| 124 | - return $clone; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Gets the request URI |
|
| 129 | - * |
|
| 130 | - * @return UriInterface |
|
| 131 | - */ |
|
| 132 | - public function getUri(): UriInterface |
|
| 133 | - { |
|
| 134 | - return $this->uri; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Creates a new instance of the request with the given URI |
|
| 139 | - * |
|
| 140 | - * @param UriInterface $uri |
|
| 141 | - * @param bool $preserveHost |
|
| 142 | - * |
|
| 143 | - * @return static |
|
| 144 | - */ |
|
| 145 | - public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface |
|
| 146 | - { |
|
| 147 | - $clone = clone $this; |
|
| 148 | - $clone->setUri($uri, $preserveHost); |
|
| 149 | - |
|
| 150 | - return $clone; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Gets the request target |
|
| 155 | - * |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 158 | - public function getRequestTarget(): string |
|
| 159 | - { |
|
| 160 | - if (isset($this->requestTarget)) { |
|
| 161 | - return $this->requestTarget; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $requestTarget = $this->uri->getPath(); |
|
| 165 | - |
|
| 166 | - // https://tools.ietf.org/html/rfc7230#section-5.3.1 |
|
| 167 | - // https://tools.ietf.org/html/rfc7230#section-2.7 |
|
| 168 | - // |
|
| 169 | - // origin-form = absolute-path [ "?" query ] |
|
| 170 | - // absolute-path = 1*( "/" segment ) |
|
| 171 | - if (strncmp($requestTarget, '/', 1) !== 0) { |
|
| 172 | - return '/'; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $queryString = $this->uri->getQuery(); |
|
| 176 | - if ($queryString !== '') { |
|
| 177 | - $requestTarget .= '?' . $queryString; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $requestTarget; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Creates a new instance of the request with the given request target |
|
| 185 | - * |
|
| 186 | - * @param mixed $requestTarget |
|
| 187 | - * |
|
| 188 | - * @return static |
|
| 189 | - * |
|
| 190 | - * @throws InvalidArgumentException |
|
| 191 | - * If the request target isn't valid. |
|
| 192 | - */ |
|
| 193 | - public function withRequestTarget($requestTarget): RequestInterface |
|
| 194 | - { |
|
| 195 | - $clone = clone $this; |
|
| 196 | - $clone->setRequestTarget($requestTarget); |
|
| 197 | - |
|
| 198 | - return $clone; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Sets the given method to the request |
|
| 203 | - * |
|
| 204 | - * @param string $method |
|
| 205 | - * |
|
| 206 | - * @return void |
|
| 207 | - * |
|
| 208 | - * @throws InvalidArgumentException |
|
| 209 | - * If the method isn't valid. |
|
| 210 | - */ |
|
| 211 | - final protected function setMethod($method): void |
|
| 212 | - { |
|
| 213 | - $this->validateMethod($method); |
|
| 214 | - |
|
| 215 | - $this->method = $method; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Sets the given URI to the request |
|
| 220 | - * |
|
| 221 | - * @param mixed $uri |
|
| 222 | - * @param bool $preserveHost |
|
| 223 | - * |
|
| 224 | - * @return void |
|
| 225 | - * |
|
| 226 | - * @throws InvalidArgumentException |
|
| 227 | - * If the URI isn't valid. |
|
| 228 | - */ |
|
| 229 | - final protected function setUri($uri, $preserveHost = false): void |
|
| 230 | - { |
|
| 231 | - $this->uri = Uri::create($uri); |
|
| 232 | - |
|
| 233 | - if ($preserveHost && $this->hasHeader('Host')) { |
|
| 234 | - return; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - $host = $this->uri->getHost(); |
|
| 238 | - if ($host === '') { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - $port = $this->uri->getPort(); |
|
| 243 | - if (isset($port)) { |
|
| 244 | - $host .= ':' . $port; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $this->setHeader('Host', $host, true); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Sets the given request target to the request |
|
| 252 | - * |
|
| 253 | - * @param mixed $requestTarget |
|
| 254 | - * |
|
| 255 | - * @return void |
|
| 256 | - * |
|
| 257 | - * @throws InvalidArgumentException |
|
| 258 | - * If the request target isn't valid. |
|
| 259 | - */ |
|
| 260 | - final protected function setRequestTarget($requestTarget): void |
|
| 261 | - { |
|
| 262 | - $this->validateRequestTarget($requestTarget); |
|
| 263 | - |
|
| 264 | - /** @var string $requestTarget */ |
|
| 265 | - |
|
| 266 | - $this->requestTarget = $requestTarget; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Validates the given method |
|
| 271 | - * |
|
| 272 | - * @link https://tools.ietf.org/html/rfc7230#section-3.1.1 |
|
| 273 | - * |
|
| 274 | - * @param mixed $method |
|
| 275 | - * |
|
| 276 | - * @return void |
|
| 277 | - * |
|
| 278 | - * @throws InvalidArgumentException |
|
| 279 | - * If the method isn't valid. |
|
| 280 | - */ |
|
| 281 | - private function validateMethod($method): void |
|
| 282 | - { |
|
| 283 | - if ('' === $method) { |
|
| 284 | - throw new InvalidArgumentException('HTTP method cannot be an empty'); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if (!is_string($method)) { |
|
| 288 | - throw new InvalidArgumentException('HTTP method must be a string'); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - if (!preg_match(HeaderInterface::RFC7230_TOKEN_REGEX, $method)) { |
|
| 292 | - throw new InvalidArgumentException('Invalid HTTP method'); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Validates the given request target |
|
| 298 | - * |
|
| 299 | - * @param mixed $requestTarget |
|
| 300 | - * |
|
| 301 | - * @return void |
|
| 302 | - * |
|
| 303 | - * @throws InvalidArgumentException |
|
| 304 | - * If the request target isn't valid. |
|
| 305 | - */ |
|
| 306 | - private function validateRequestTarget($requestTarget): void |
|
| 307 | - { |
|
| 308 | - if ('' === $requestTarget) { |
|
| 309 | - throw new InvalidArgumentException('HTTP request target cannot be an empty'); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if (!is_string($requestTarget)) { |
|
| 313 | - throw new InvalidArgumentException('HTTP request target must be a string'); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - if (!preg_match(self::RFC7230_REQUEST_TARGET_REGEX, $requestTarget)) { |
|
| 317 | - throw new InvalidArgumentException('Invalid HTTP request target'); |
|
| 318 | - } |
|
| 319 | - } |
|
| 39 | + /** |
|
| 40 | + * Regular Expression used for a request target validation |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + private const RFC7230_REQUEST_TARGET_REGEX = '/^[\x21-\x7E\x80-\xFF]+$/'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * The request method (aka verb) |
|
| 48 | + * |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + private string $method = self::METHOD_GET; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * The request URI |
|
| 55 | + * |
|
| 56 | + * @var UriInterface |
|
| 57 | + */ |
|
| 58 | + private UriInterface $uri; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The request target |
|
| 62 | + * |
|
| 63 | + * @var string|null |
|
| 64 | + */ |
|
| 65 | + private ?string $requestTarget = null; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Constructor of the class |
|
| 69 | + * |
|
| 70 | + * @param string|null $method |
|
| 71 | + * @param mixed $uri |
|
| 72 | + * @param array<string, string|string[]>|null $headers |
|
| 73 | + * @param StreamInterface|null $body |
|
| 74 | + * |
|
| 75 | + * @throws InvalidArgumentException |
|
| 76 | + * If one of the arguments isn't valid. |
|
| 77 | + */ |
|
| 78 | + public function __construct( |
|
| 79 | + ?string $method = null, |
|
| 80 | + $uri = null, |
|
| 81 | + ?array $headers = null, |
|
| 82 | + ?StreamInterface $body = null |
|
| 83 | + ) { |
|
| 84 | + if (isset($method)) { |
|
| 85 | + $this->setMethod($method); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $this->setUri($uri ?? '/'); |
|
| 89 | + |
|
| 90 | + if (isset($headers)) { |
|
| 91 | + $this->setHeaders($headers); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if (isset($body)) { |
|
| 95 | + $this->setBody($body); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Gets the request method |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + public function getMethod(): string |
|
| 105 | + { |
|
| 106 | + return $this->method; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Creates a new instance of the request with the given method |
|
| 111 | + * |
|
| 112 | + * @param string $method |
|
| 113 | + * |
|
| 114 | + * @return static |
|
| 115 | + * |
|
| 116 | + * @throws InvalidArgumentException |
|
| 117 | + * If the method isn't valid. |
|
| 118 | + */ |
|
| 119 | + public function withMethod($method): RequestInterface |
|
| 120 | + { |
|
| 121 | + $clone = clone $this; |
|
| 122 | + $clone->setMethod($method); |
|
| 123 | + |
|
| 124 | + return $clone; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Gets the request URI |
|
| 129 | + * |
|
| 130 | + * @return UriInterface |
|
| 131 | + */ |
|
| 132 | + public function getUri(): UriInterface |
|
| 133 | + { |
|
| 134 | + return $this->uri; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Creates a new instance of the request with the given URI |
|
| 139 | + * |
|
| 140 | + * @param UriInterface $uri |
|
| 141 | + * @param bool $preserveHost |
|
| 142 | + * |
|
| 143 | + * @return static |
|
| 144 | + */ |
|
| 145 | + public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface |
|
| 146 | + { |
|
| 147 | + $clone = clone $this; |
|
| 148 | + $clone->setUri($uri, $preserveHost); |
|
| 149 | + |
|
| 150 | + return $clone; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Gets the request target |
|
| 155 | + * |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | + public function getRequestTarget(): string |
|
| 159 | + { |
|
| 160 | + if (isset($this->requestTarget)) { |
|
| 161 | + return $this->requestTarget; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $requestTarget = $this->uri->getPath(); |
|
| 165 | + |
|
| 166 | + // https://tools.ietf.org/html/rfc7230#section-5.3.1 |
|
| 167 | + // https://tools.ietf.org/html/rfc7230#section-2.7 |
|
| 168 | + // |
|
| 169 | + // origin-form = absolute-path [ "?" query ] |
|
| 170 | + // absolute-path = 1*( "/" segment ) |
|
| 171 | + if (strncmp($requestTarget, '/', 1) !== 0) { |
|
| 172 | + return '/'; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $queryString = $this->uri->getQuery(); |
|
| 176 | + if ($queryString !== '') { |
|
| 177 | + $requestTarget .= '?' . $queryString; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $requestTarget; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Creates a new instance of the request with the given request target |
|
| 185 | + * |
|
| 186 | + * @param mixed $requestTarget |
|
| 187 | + * |
|
| 188 | + * @return static |
|
| 189 | + * |
|
| 190 | + * @throws InvalidArgumentException |
|
| 191 | + * If the request target isn't valid. |
|
| 192 | + */ |
|
| 193 | + public function withRequestTarget($requestTarget): RequestInterface |
|
| 194 | + { |
|
| 195 | + $clone = clone $this; |
|
| 196 | + $clone->setRequestTarget($requestTarget); |
|
| 197 | + |
|
| 198 | + return $clone; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Sets the given method to the request |
|
| 203 | + * |
|
| 204 | + * @param string $method |
|
| 205 | + * |
|
| 206 | + * @return void |
|
| 207 | + * |
|
| 208 | + * @throws InvalidArgumentException |
|
| 209 | + * If the method isn't valid. |
|
| 210 | + */ |
|
| 211 | + final protected function setMethod($method): void |
|
| 212 | + { |
|
| 213 | + $this->validateMethod($method); |
|
| 214 | + |
|
| 215 | + $this->method = $method; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Sets the given URI to the request |
|
| 220 | + * |
|
| 221 | + * @param mixed $uri |
|
| 222 | + * @param bool $preserveHost |
|
| 223 | + * |
|
| 224 | + * @return void |
|
| 225 | + * |
|
| 226 | + * @throws InvalidArgumentException |
|
| 227 | + * If the URI isn't valid. |
|
| 228 | + */ |
|
| 229 | + final protected function setUri($uri, $preserveHost = false): void |
|
| 230 | + { |
|
| 231 | + $this->uri = Uri::create($uri); |
|
| 232 | + |
|
| 233 | + if ($preserveHost && $this->hasHeader('Host')) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + $host = $this->uri->getHost(); |
|
| 238 | + if ($host === '') { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + $port = $this->uri->getPort(); |
|
| 243 | + if (isset($port)) { |
|
| 244 | + $host .= ':' . $port; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $this->setHeader('Host', $host, true); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Sets the given request target to the request |
|
| 252 | + * |
|
| 253 | + * @param mixed $requestTarget |
|
| 254 | + * |
|
| 255 | + * @return void |
|
| 256 | + * |
|
| 257 | + * @throws InvalidArgumentException |
|
| 258 | + * If the request target isn't valid. |
|
| 259 | + */ |
|
| 260 | + final protected function setRequestTarget($requestTarget): void |
|
| 261 | + { |
|
| 262 | + $this->validateRequestTarget($requestTarget); |
|
| 263 | + |
|
| 264 | + /** @var string $requestTarget */ |
|
| 265 | + |
|
| 266 | + $this->requestTarget = $requestTarget; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Validates the given method |
|
| 271 | + * |
|
| 272 | + * @link https://tools.ietf.org/html/rfc7230#section-3.1.1 |
|
| 273 | + * |
|
| 274 | + * @param mixed $method |
|
| 275 | + * |
|
| 276 | + * @return void |
|
| 277 | + * |
|
| 278 | + * @throws InvalidArgumentException |
|
| 279 | + * If the method isn't valid. |
|
| 280 | + */ |
|
| 281 | + private function validateMethod($method): void |
|
| 282 | + { |
|
| 283 | + if ('' === $method) { |
|
| 284 | + throw new InvalidArgumentException('HTTP method cannot be an empty'); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if (!is_string($method)) { |
|
| 288 | + throw new InvalidArgumentException('HTTP method must be a string'); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + if (!preg_match(HeaderInterface::RFC7230_TOKEN_REGEX, $method)) { |
|
| 292 | + throw new InvalidArgumentException('Invalid HTTP method'); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Validates the given request target |
|
| 298 | + * |
|
| 299 | + * @param mixed $requestTarget |
|
| 300 | + * |
|
| 301 | + * @return void |
|
| 302 | + * |
|
| 303 | + * @throws InvalidArgumentException |
|
| 304 | + * If the request target isn't valid. |
|
| 305 | + */ |
|
| 306 | + private function validateRequestTarget($requestTarget): void |
|
| 307 | + { |
|
| 308 | + if ('' === $requestTarget) { |
|
| 309 | + throw new InvalidArgumentException('HTTP request target cannot be an empty'); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if (!is_string($requestTarget)) { |
|
| 313 | + throw new InvalidArgumentException('HTTP request target must be a string'); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + if (!preg_match(self::RFC7230_REQUEST_TARGET_REGEX, $requestTarget)) { |
|
| 317 | + throw new InvalidArgumentException('Invalid HTTP request target'); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | 320 | } |
@@ -26,63 +26,63 @@ |
||
| 26 | 26 | class ServerRequestFactory implements ServerRequestFactoryInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Creates a new request from superglobals variables |
|
| 31 | - * |
|
| 32 | - * @param array<array-key, mixed>|null $serverParams |
|
| 33 | - * @param array<array-key, mixed>|null $queryParams |
|
| 34 | - * @param array<array-key, mixed>|null $cookieParams |
|
| 35 | - * @param array<array-key, mixed>|null $uploadedFiles |
|
| 36 | - * @param array<array-key, mixed>|null $parsedBody |
|
| 37 | - * |
|
| 38 | - * @return ServerRequestInterface |
|
| 39 | - * |
|
| 40 | - * @link http://php.net/manual/en/language.variables.superglobals.php |
|
| 41 | - * @link https://www.php-fig.org/psr/psr-15/meta/ |
|
| 42 | - */ |
|
| 43 | - public static function fromGlobals( |
|
| 44 | - ?array $serverParams = null, |
|
| 45 | - ?array $queryParams = null, |
|
| 46 | - ?array $cookieParams = null, |
|
| 47 | - ?array $uploadedFiles = null, |
|
| 48 | - ?array $parsedBody = null |
|
| 49 | - ): ServerRequestInterface { |
|
| 50 | - $serverParams ??= $_SERVER; |
|
| 51 | - $queryParams ??= $_GET; |
|
| 52 | - $cookieParams ??= $_COOKIE; |
|
| 53 | - $uploadedFiles ??= $_FILES; |
|
| 54 | - $parsedBody ??= $_POST; |
|
| 29 | + /** |
|
| 30 | + * Creates a new request from superglobals variables |
|
| 31 | + * |
|
| 32 | + * @param array<array-key, mixed>|null $serverParams |
|
| 33 | + * @param array<array-key, mixed>|null $queryParams |
|
| 34 | + * @param array<array-key, mixed>|null $cookieParams |
|
| 35 | + * @param array<array-key, mixed>|null $uploadedFiles |
|
| 36 | + * @param array<array-key, mixed>|null $parsedBody |
|
| 37 | + * |
|
| 38 | + * @return ServerRequestInterface |
|
| 39 | + * |
|
| 40 | + * @link http://php.net/manual/en/language.variables.superglobals.php |
|
| 41 | + * @link https://www.php-fig.org/psr/psr-15/meta/ |
|
| 42 | + */ |
|
| 43 | + public static function fromGlobals( |
|
| 44 | + ?array $serverParams = null, |
|
| 45 | + ?array $queryParams = null, |
|
| 46 | + ?array $cookieParams = null, |
|
| 47 | + ?array $uploadedFiles = null, |
|
| 48 | + ?array $parsedBody = null |
|
| 49 | + ): ServerRequestInterface { |
|
| 50 | + $serverParams ??= $_SERVER; |
|
| 51 | + $queryParams ??= $_GET; |
|
| 52 | + $cookieParams ??= $_COOKIE; |
|
| 53 | + $uploadedFiles ??= $_FILES; |
|
| 54 | + $parsedBody ??= $_POST; |
|
| 55 | 55 | |
| 56 | - return new ServerRequest( |
|
| 57 | - server_request_protocol_version($serverParams), |
|
| 58 | - server_request_method($serverParams), |
|
| 59 | - server_request_uri($serverParams), |
|
| 60 | - server_request_headers($serverParams), |
|
| 61 | - new PhpInputStream(), |
|
| 62 | - $serverParams, |
|
| 63 | - $queryParams, |
|
| 64 | - $cookieParams, |
|
| 65 | - server_request_files($uploadedFiles), |
|
| 66 | - $parsedBody |
|
| 67 | - ); |
|
| 68 | - } |
|
| 56 | + return new ServerRequest( |
|
| 57 | + server_request_protocol_version($serverParams), |
|
| 58 | + server_request_method($serverParams), |
|
| 59 | + server_request_uri($serverParams), |
|
| 60 | + server_request_headers($serverParams), |
|
| 61 | + new PhpInputStream(), |
|
| 62 | + $serverParams, |
|
| 63 | + $queryParams, |
|
| 64 | + $cookieParams, |
|
| 65 | + server_request_files($uploadedFiles), |
|
| 66 | + $parsedBody |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Creates a new request |
|
| 72 | - * |
|
| 73 | - * @param string $method |
|
| 74 | - * @param mixed $uri |
|
| 75 | - * @param array<array-key, mixed> $serverParams |
|
| 76 | - */ |
|
| 77 | - public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface |
|
| 78 | - { |
|
| 79 | - return new ServerRequest( |
|
| 80 | - server_request_protocol_version($serverParams), |
|
| 81 | - $method, |
|
| 82 | - $uri, |
|
| 83 | - server_request_headers($serverParams), |
|
| 84 | - null, // body |
|
| 85 | - $serverParams |
|
| 86 | - ); |
|
| 87 | - } |
|
| 70 | + /** |
|
| 71 | + * Creates a new request |
|
| 72 | + * |
|
| 73 | + * @param string $method |
|
| 74 | + * @param mixed $uri |
|
| 75 | + * @param array<array-key, mixed> $serverParams |
|
| 76 | + */ |
|
| 77 | + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface |
|
| 78 | + { |
|
| 79 | + return new ServerRequest( |
|
| 80 | + server_request_protocol_version($serverParams), |
|
| 81 | + $method, |
|
| 82 | + $uri, |
|
| 83 | + server_request_headers($serverParams), |
|
| 84 | + null, // body |
|
| 85 | + $serverParams |
|
| 86 | + ); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -31,56 +31,56 @@ |
||
| 31 | 31 | final class Fragment implements ComponentInterface |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Regular expression used for the component normalization |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - // phpcs:ignore Generic.Files.LineLength |
|
| 40 | - private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x3b\x3d\x3f-\x5a\x5f\x61-\x7a\x7e])*|(.?)/u'; |
|
| 34 | + /** |
|
| 35 | + * Regular expression used for the component normalization |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + // phpcs:ignore Generic.Files.LineLength |
|
| 40 | + private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x3b\x3d\x3f-\x5a\x5f\x61-\x7a\x7e])*|(.?)/u'; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The component value |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - private string $value = ''; |
|
| 42 | + /** |
|
| 43 | + * The component value |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + private string $value = ''; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Constructor of the class |
|
| 51 | - * |
|
| 52 | - * @param mixed $value |
|
| 53 | - * |
|
| 54 | - * @throws InvalidArgumentException |
|
| 55 | - * If the component isn't valid. |
|
| 56 | - */ |
|
| 57 | - public function __construct($value) |
|
| 58 | - { |
|
| 59 | - if ($value === '') { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 49 | + /** |
|
| 50 | + * Constructor of the class |
|
| 51 | + * |
|
| 52 | + * @param mixed $value |
|
| 53 | + * |
|
| 54 | + * @throws InvalidArgumentException |
|
| 55 | + * If the component isn't valid. |
|
| 56 | + */ |
|
| 57 | + public function __construct($value) |
|
| 58 | + { |
|
| 59 | + if ($value === '') { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - if (!is_string($value)) { |
|
| 64 | - throw new InvalidArgumentException('URI component "fragment" must be a string'); |
|
| 65 | - } |
|
| 63 | + if (!is_string($value)) { |
|
| 64 | + throw new InvalidArgumentException('URI component "fragment" must be a string'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $this->value = (string) preg_replace_callback( |
|
| 68 | - self::NORMALIZATION_REGEX, |
|
| 69 | - static function (array $match): string { |
|
| 70 | - /** @var array{0: string, 1?: string} $match */ |
|
| 71 | - return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 72 | - }, |
|
| 73 | - $value |
|
| 74 | - ); |
|
| 75 | - } |
|
| 67 | + $this->value = (string) preg_replace_callback( |
|
| 68 | + self::NORMALIZATION_REGEX, |
|
| 69 | + static function (array $match): string { |
|
| 70 | + /** @var array{0: string, 1?: string} $match */ |
|
| 71 | + return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 72 | + }, |
|
| 73 | + $value |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * {@inheritdoc} |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getValue(): string |
|
| 83 | - { |
|
| 84 | - return $this->value; |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * {@inheritdoc} |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getValue(): string |
|
| 83 | + { |
|
| 84 | + return $this->value; |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | |
| 67 | 67 | $this->value = (string) preg_replace_callback( |
| 68 | 68 | self::NORMALIZATION_REGEX, |
| 69 | - static function (array $match): string { |
|
| 69 | + static function(array $match): string { |
|
| 70 | 70 | /** @var array{0: string, 1?: string} $match */ |
| 71 | 71 | return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
| 72 | 72 | }, |
@@ -31,74 +31,74 @@ |
||
| 31 | 31 | final class Password implements ComponentInterface |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Regular expression used for the component normalization |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - // phpcs:ignore Generic.Files.LineLength |
|
| 40 | - private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u'; |
|
| 34 | + /** |
|
| 35 | + * Regular expression used for the component normalization |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + // phpcs:ignore Generic.Files.LineLength |
|
| 40 | + private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u'; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The component value |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - private string $value = ''; |
|
| 42 | + /** |
|
| 43 | + * The component value |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + private string $value = ''; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Constructor of the class |
|
| 51 | - * |
|
| 52 | - * @param mixed $value |
|
| 53 | - * |
|
| 54 | - * @throws InvalidArgumentException |
|
| 55 | - * If the component isn't valid. |
|
| 56 | - */ |
|
| 57 | - public function __construct($value) |
|
| 58 | - { |
|
| 59 | - if ($value === '') { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 49 | + /** |
|
| 50 | + * Constructor of the class |
|
| 51 | + * |
|
| 52 | + * @param mixed $value |
|
| 53 | + * |
|
| 54 | + * @throws InvalidArgumentException |
|
| 55 | + * If the component isn't valid. |
|
| 56 | + */ |
|
| 57 | + public function __construct($value) |
|
| 58 | + { |
|
| 59 | + if ($value === '') { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - if (!is_string($value)) { |
|
| 64 | - throw new InvalidArgumentException('URI component "password" must be a string'); |
|
| 65 | - } |
|
| 63 | + if (!is_string($value)) { |
|
| 64 | + throw new InvalidArgumentException('URI component "password" must be a string'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $this->value = (string) preg_replace_callback( |
|
| 68 | - self::NORMALIZATION_REGEX, |
|
| 69 | - static function (array $match): string { |
|
| 70 | - /** @var array{0: string, 1?: string} $match */ |
|
| 71 | - return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 72 | - }, |
|
| 73 | - $value |
|
| 74 | - ); |
|
| 75 | - } |
|
| 67 | + $this->value = (string) preg_replace_callback( |
|
| 68 | + self::NORMALIZATION_REGEX, |
|
| 69 | + static function (array $match): string { |
|
| 70 | + /** @var array{0: string, 1?: string} $match */ |
|
| 71 | + return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 72 | + }, |
|
| 73 | + $value |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Creates a password component |
|
| 79 | - * |
|
| 80 | - * @param mixed $password |
|
| 81 | - * |
|
| 82 | - * @return Password |
|
| 83 | - * |
|
| 84 | - * @throws InvalidArgumentException |
|
| 85 | - */ |
|
| 86 | - public static function create($password): Password |
|
| 87 | - { |
|
| 88 | - if ($password instanceof Password) { |
|
| 89 | - return $password; |
|
| 90 | - } |
|
| 77 | + /** |
|
| 78 | + * Creates a password component |
|
| 79 | + * |
|
| 80 | + * @param mixed $password |
|
| 81 | + * |
|
| 82 | + * @return Password |
|
| 83 | + * |
|
| 84 | + * @throws InvalidArgumentException |
|
| 85 | + */ |
|
| 86 | + public static function create($password): Password |
|
| 87 | + { |
|
| 88 | + if ($password instanceof Password) { |
|
| 89 | + return $password; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return new Password($password); |
|
| 93 | - } |
|
| 92 | + return new Password($password); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * {@inheritdoc} |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function getValue(): string |
|
| 101 | - { |
|
| 102 | - return $this->value; |
|
| 103 | - } |
|
| 95 | + /** |
|
| 96 | + * {@inheritdoc} |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function getValue(): string |
|
| 101 | + { |
|
| 102 | + return $this->value; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | |
| 67 | 67 | $this->value = (string) preg_replace_callback( |
| 68 | 68 | self::NORMALIZATION_REGEX, |
| 69 | - static function (array $match): string { |
|
| 69 | + static function(array $match): string { |
|
| 70 | 70 | /** @var array{0: string, 1?: string} $match */ |
| 71 | 71 | return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
| 72 | 72 | }, |
@@ -32,59 +32,59 @@ |
||
| 32 | 32 | final class Host implements ComponentInterface |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Regular expression used for the component normalization |
|
| 37 | - * |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - // phpcs:ignore Generic.Files.LineLength |
|
| 41 | - private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u'; |
|
| 35 | + /** |
|
| 36 | + * Regular expression used for the component normalization |
|
| 37 | + * |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + // phpcs:ignore Generic.Files.LineLength |
|
| 41 | + private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u'; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * The component value |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - private string $value = ''; |
|
| 43 | + /** |
|
| 44 | + * The component value |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + private string $value = ''; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Constructor of the class |
|
| 52 | - * |
|
| 53 | - * @param mixed $value |
|
| 54 | - * |
|
| 55 | - * @throws InvalidArgumentException |
|
| 56 | - * If the component isn't valid. |
|
| 57 | - */ |
|
| 58 | - public function __construct($value) |
|
| 59 | - { |
|
| 60 | - if ($value === '') { |
|
| 61 | - return; |
|
| 62 | - } |
|
| 50 | + /** |
|
| 51 | + * Constructor of the class |
|
| 52 | + * |
|
| 53 | + * @param mixed $value |
|
| 54 | + * |
|
| 55 | + * @throws InvalidArgumentException |
|
| 56 | + * If the component isn't valid. |
|
| 57 | + */ |
|
| 58 | + public function __construct($value) |
|
| 59 | + { |
|
| 60 | + if ($value === '') { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - if (!is_string($value)) { |
|
| 65 | - throw new InvalidArgumentException('URI component "host" must be a string'); |
|
| 66 | - } |
|
| 64 | + if (!is_string($value)) { |
|
| 65 | + throw new InvalidArgumentException('URI component "host" must be a string'); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $this->value = (string) preg_replace_callback( |
|
| 69 | - self::NORMALIZATION_REGEX, |
|
| 70 | - static function (array $match): string { |
|
| 71 | - /** @var array{0: string, 1?: string} $match */ |
|
| 72 | - return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 73 | - }, |
|
| 74 | - $value |
|
| 75 | - ); |
|
| 68 | + $this->value = (string) preg_replace_callback( |
|
| 69 | + self::NORMALIZATION_REGEX, |
|
| 70 | + static function (array $match): string { |
|
| 71 | + /** @var array{0: string, 1?: string} $match */ |
|
| 72 | + return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 73 | + }, |
|
| 74 | + $value |
|
| 75 | + ); |
|
| 76 | 76 | |
| 77 | - // the component is case-insensitive... |
|
| 78 | - $this->value = strtolower($this->value); |
|
| 79 | - } |
|
| 77 | + // the component is case-insensitive... |
|
| 78 | + $this->value = strtolower($this->value); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * {@inheritdoc} |
|
| 83 | - * |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public function getValue(): string |
|
| 87 | - { |
|
| 88 | - return $this->value; |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * {@inheritdoc} |
|
| 83 | + * |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public function getValue(): string |
|
| 87 | + { |
|
| 88 | + return $this->value; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | |
| 68 | 68 | $this->value = (string) preg_replace_callback( |
| 69 | 69 | self::NORMALIZATION_REGEX, |
| 70 | - static function (array $match): string { |
|
| 70 | + static function(array $match): string { |
|
| 71 | 71 | /** @var array{0: string, 1?: string} $match */ |
| 72 | 72 | return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
| 73 | 73 | }, |
@@ -31,56 +31,56 @@ |
||
| 31 | 31 | final class Path implements ComponentInterface |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Regular expression used for the component normalization |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - // phpcs:ignore Generic.Files.LineLength |
|
| 40 | - private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x3b\x3d\x40-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u'; |
|
| 34 | + /** |
|
| 35 | + * Regular expression used for the component normalization |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + // phpcs:ignore Generic.Files.LineLength |
|
| 40 | + private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x3b\x3d\x40-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u'; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The component value |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - private string $value = ''; |
|
| 42 | + /** |
|
| 43 | + * The component value |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + private string $value = ''; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Constructor of the class |
|
| 51 | - * |
|
| 52 | - * @param mixed $value |
|
| 53 | - * |
|
| 54 | - * @throws InvalidArgumentException |
|
| 55 | - * If the component isn't valid. |
|
| 56 | - */ |
|
| 57 | - public function __construct($value) |
|
| 58 | - { |
|
| 59 | - if ($value === '') { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 49 | + /** |
|
| 50 | + * Constructor of the class |
|
| 51 | + * |
|
| 52 | + * @param mixed $value |
|
| 53 | + * |
|
| 54 | + * @throws InvalidArgumentException |
|
| 55 | + * If the component isn't valid. |
|
| 56 | + */ |
|
| 57 | + public function __construct($value) |
|
| 58 | + { |
|
| 59 | + if ($value === '') { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - if (!is_string($value)) { |
|
| 64 | - throw new InvalidArgumentException('URI component "path" must be a string'); |
|
| 65 | - } |
|
| 63 | + if (!is_string($value)) { |
|
| 64 | + throw new InvalidArgumentException('URI component "path" must be a string'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $this->value = (string) preg_replace_callback( |
|
| 68 | - self::NORMALIZATION_REGEX, |
|
| 69 | - static function (array $match): string { |
|
| 70 | - /** @var array{0: string, 1?: string} $match */ |
|
| 71 | - return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 72 | - }, |
|
| 73 | - $value |
|
| 74 | - ); |
|
| 75 | - } |
|
| 67 | + $this->value = (string) preg_replace_callback( |
|
| 68 | + self::NORMALIZATION_REGEX, |
|
| 69 | + static function (array $match): string { |
|
| 70 | + /** @var array{0: string, 1?: string} $match */ |
|
| 71 | + return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 72 | + }, |
|
| 73 | + $value |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * {@inheritdoc} |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getValue(): string |
|
| 83 | - { |
|
| 84 | - return $this->value; |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * {@inheritdoc} |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getValue(): string |
|
| 83 | + { |
|
| 84 | + return $this->value; |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | |
| 67 | 67 | $this->value = (string) preg_replace_callback( |
| 68 | 68 | self::NORMALIZATION_REGEX, |
| 69 | - static function (array $match): string { |
|
| 69 | + static function(array $match): string { |
|
| 70 | 70 | /** @var array{0: string, 1?: string} $match */ |
| 71 | 71 | return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
| 72 | 72 | }, |