@@ -25,39 +25,39 @@ |
||
| 25 | 25 | class ContentLocationHeader extends Header |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var UriInterface |
|
| 30 | - */ |
|
| 31 | - private UriInterface $uri; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Constructor of the class |
|
| 35 | - * |
|
| 36 | - * @param mixed $uri |
|
| 37 | - * |
|
| 38 | - * @throws InvalidUriException |
|
| 39 | - * If the URI isn't valid. |
|
| 40 | - */ |
|
| 41 | - public function __construct($uri) |
|
| 42 | - { |
|
| 43 | - $uri = Uri::create($uri); |
|
| 44 | - |
|
| 45 | - $this->uri = $uri; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - */ |
|
| 51 | - public function getFieldName(): string |
|
| 52 | - { |
|
| 53 | - return 'Content-Location'; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * {@inheritdoc} |
|
| 58 | - */ |
|
| 59 | - public function getFieldValue(): string |
|
| 60 | - { |
|
| 61 | - return $this->uri->__toString(); |
|
| 62 | - } |
|
| 28 | + /** |
|
| 29 | + * @var UriInterface |
|
| 30 | + */ |
|
| 31 | + private UriInterface $uri; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Constructor of the class |
|
| 35 | + * |
|
| 36 | + * @param mixed $uri |
|
| 37 | + * |
|
| 38 | + * @throws InvalidUriException |
|
| 39 | + * If the URI isn't valid. |
|
| 40 | + */ |
|
| 41 | + public function __construct($uri) |
|
| 42 | + { |
|
| 43 | + $uri = Uri::create($uri); |
|
| 44 | + |
|
| 45 | + $this->uri = $uri; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + */ |
|
| 51 | + public function getFieldName(): string |
|
| 52 | + { |
|
| 53 | + return 'Content-Location'; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * {@inheritdoc} |
|
| 58 | + */ |
|
| 59 | + public function getFieldValue(): string |
|
| 60 | + { |
|
| 61 | + return $this->uri->__toString(); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -32,34 +32,34 @@ |
||
| 32 | 32 | class CookieHeader extends Header |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - private array $value; |
|
| 35 | + /** |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + private array $value; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor of the class |
|
| 42 | - * |
|
| 43 | - * @param array $value |
|
| 44 | - */ |
|
| 45 | - public function __construct(array $value = []) |
|
| 46 | - { |
|
| 47 | - $this->value = $value; |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor of the class |
|
| 42 | + * |
|
| 43 | + * @param array $value |
|
| 44 | + */ |
|
| 45 | + public function __construct(array $value = []) |
|
| 46 | + { |
|
| 47 | + $this->value = $value; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * {@inheritdoc} |
|
| 52 | - */ |
|
| 53 | - public function getFieldName(): string |
|
| 54 | - { |
|
| 55 | - return 'Cookie'; |
|
| 56 | - } |
|
| 50 | + /** |
|
| 51 | + * {@inheritdoc} |
|
| 52 | + */ |
|
| 53 | + public function getFieldName(): string |
|
| 54 | + { |
|
| 55 | + return 'Cookie'; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritdoc} |
|
| 60 | - */ |
|
| 61 | - public function getFieldValue(): string |
|
| 62 | - { |
|
| 63 | - return http_build_query($this->value, '', '; ', PHP_QUERY_RFC3986); |
|
| 64 | - } |
|
| 58 | + /** |
|
| 59 | + * {@inheritdoc} |
|
| 60 | + */ |
|
| 61 | + public function getFieldValue(): string |
|
| 62 | + { |
|
| 63 | + return http_build_query($this->value, '', '; ', PHP_QUERY_RFC3986); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -28,41 +28,41 @@ |
||
| 28 | 28 | class AccessControlExposeHeadersHeader extends Header |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var list<string> |
|
| 33 | - */ |
|
| 34 | - private array $headers; |
|
| 31 | + /** |
|
| 32 | + * @var list<string> |
|
| 33 | + */ |
|
| 34 | + private array $headers; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor of the class |
|
| 38 | - * |
|
| 39 | - * @param string ...$headers |
|
| 40 | - * |
|
| 41 | - * @throws InvalidHeaderValueException |
|
| 42 | - * If one of the header names isn't valid. |
|
| 43 | - */ |
|
| 44 | - public function __construct(string ...$headers) |
|
| 45 | - { |
|
| 46 | - /** @var list<string> $headers */ |
|
| 36 | + /** |
|
| 37 | + * Constructor of the class |
|
| 38 | + * |
|
| 39 | + * @param string ...$headers |
|
| 40 | + * |
|
| 41 | + * @throws InvalidHeaderValueException |
|
| 42 | + * If one of the header names isn't valid. |
|
| 43 | + */ |
|
| 44 | + public function __construct(string ...$headers) |
|
| 45 | + { |
|
| 46 | + /** @var list<string> $headers */ |
|
| 47 | 47 | |
| 48 | - $this->validateToken(...$headers); |
|
| 48 | + $this->validateToken(...$headers); |
|
| 49 | 49 | |
| 50 | - $this->headers = $headers; |
|
| 51 | - } |
|
| 50 | + $this->headers = $headers; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritdoc} |
|
| 55 | - */ |
|
| 56 | - public function getFieldName(): string |
|
| 57 | - { |
|
| 58 | - return 'Access-Control-Expose-Headers'; |
|
| 59 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritdoc} |
|
| 55 | + */ |
|
| 56 | + public function getFieldName(): string |
|
| 57 | + { |
|
| 58 | + return 'Access-Control-Expose-Headers'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritdoc} |
|
| 63 | - */ |
|
| 64 | - public function getFieldValue(): string |
|
| 65 | - { |
|
| 66 | - return implode(', ', $this->headers); |
|
| 67 | - } |
|
| 61 | + /** |
|
| 62 | + * {@inheritdoc} |
|
| 63 | + */ |
|
| 64 | + public function getFieldValue(): string |
|
| 65 | + { |
|
| 66 | + return implode(', ', $this->headers); |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -28,41 +28,41 @@ |
||
| 28 | 28 | class VaryHeader extends Header |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var list<string> |
|
| 33 | - */ |
|
| 34 | - private array $value; |
|
| 31 | + /** |
|
| 32 | + * @var list<string> |
|
| 33 | + */ |
|
| 34 | + private array $value; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor of the class |
|
| 38 | - * |
|
| 39 | - * @param string ...$value |
|
| 40 | - * |
|
| 41 | - * @throws InvalidHeaderValueException |
|
| 42 | - * If one of the values isn't valid. |
|
| 43 | - */ |
|
| 44 | - public function __construct(string ...$value) |
|
| 45 | - { |
|
| 46 | - /** @var list<string> $value */ |
|
| 36 | + /** |
|
| 37 | + * Constructor of the class |
|
| 38 | + * |
|
| 39 | + * @param string ...$value |
|
| 40 | + * |
|
| 41 | + * @throws InvalidHeaderValueException |
|
| 42 | + * If one of the values isn't valid. |
|
| 43 | + */ |
|
| 44 | + public function __construct(string ...$value) |
|
| 45 | + { |
|
| 46 | + /** @var list<string> $value */ |
|
| 47 | 47 | |
| 48 | - $this->validateToken(...$value); |
|
| 48 | + $this->validateToken(...$value); |
|
| 49 | 49 | |
| 50 | - $this->value = $value; |
|
| 51 | - } |
|
| 50 | + $this->value = $value; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritdoc} |
|
| 55 | - */ |
|
| 56 | - public function getFieldName(): string |
|
| 57 | - { |
|
| 58 | - return 'Vary'; |
|
| 59 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritdoc} |
|
| 55 | + */ |
|
| 56 | + public function getFieldName(): string |
|
| 57 | + { |
|
| 58 | + return 'Vary'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritdoc} |
|
| 63 | - */ |
|
| 64 | - public function getFieldValue(): string |
|
| 65 | - { |
|
| 66 | - return implode(', ', $this->value); |
|
| 67 | - } |
|
| 61 | + /** |
|
| 62 | + * {@inheritdoc} |
|
| 63 | + */ |
|
| 64 | + public function getFieldValue(): string |
|
| 65 | + { |
|
| 66 | + return implode(', ', $this->value); |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -29,56 +29,56 @@ |
||
| 29 | 29 | class ContentDispositionHeader extends Header |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - private string $type; |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + private string $type; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var array<string, string> |
|
| 39 | - */ |
|
| 40 | - private array $parameters; |
|
| 37 | + /** |
|
| 38 | + * @var array<string, string> |
|
| 39 | + */ |
|
| 40 | + private array $parameters; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor of the class |
|
| 44 | - * |
|
| 45 | - * @param string $type |
|
| 46 | - * @param array<array-key, mixed> $parameters |
|
| 47 | - * |
|
| 48 | - * @throws InvalidHeaderValueException |
|
| 49 | - * If the type isn't valid. |
|
| 50 | - * |
|
| 51 | - * @throws InvalidHeaderValueParameterException |
|
| 52 | - * If the parameters aren't valid. |
|
| 53 | - */ |
|
| 54 | - public function __construct(string $type, array $parameters = []) |
|
| 55 | - { |
|
| 56 | - $this->validateToken($type); |
|
| 42 | + /** |
|
| 43 | + * Constructor of the class |
|
| 44 | + * |
|
| 45 | + * @param string $type |
|
| 46 | + * @param array<array-key, mixed> $parameters |
|
| 47 | + * |
|
| 48 | + * @throws InvalidHeaderValueException |
|
| 49 | + * If the type isn't valid. |
|
| 50 | + * |
|
| 51 | + * @throws InvalidHeaderValueParameterException |
|
| 52 | + * If the parameters aren't valid. |
|
| 53 | + */ |
|
| 54 | + public function __construct(string $type, array $parameters = []) |
|
| 55 | + { |
|
| 56 | + $this->validateToken($type); |
|
| 57 | 57 | |
| 58 | - $parameters = $this->validateParameters($parameters); |
|
| 58 | + $parameters = $this->validateParameters($parameters); |
|
| 59 | 59 | |
| 60 | - $this->type = $type; |
|
| 61 | - $this->parameters = $parameters; |
|
| 62 | - } |
|
| 60 | + $this->type = $type; |
|
| 61 | + $this->parameters = $parameters; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * {@inheritdoc} |
|
| 66 | - */ |
|
| 67 | - public function getFieldName(): string |
|
| 68 | - { |
|
| 69 | - return 'Content-Disposition'; |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * {@inheritdoc} |
|
| 66 | + */ |
|
| 67 | + public function getFieldName(): string |
|
| 68 | + { |
|
| 69 | + return 'Content-Disposition'; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * {@inheritdoc} |
|
| 74 | - */ |
|
| 75 | - public function getFieldValue(): string |
|
| 76 | - { |
|
| 77 | - $v = $this->type; |
|
| 78 | - foreach ($this->parameters as $name => $value) { |
|
| 79 | - $v .= sprintf('; %s="%s"', $name, $value); |
|
| 80 | - } |
|
| 72 | + /** |
|
| 73 | + * {@inheritdoc} |
|
| 74 | + */ |
|
| 75 | + public function getFieldValue(): string |
|
| 76 | + { |
|
| 77 | + $v = $this->type; |
|
| 78 | + foreach ($this->parameters as $name => $value) { |
|
| 79 | + $v .= sprintf('; %s="%s"', $name, $value); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return $v; |
|
| 83 | - } |
|
| 82 | + return $v; |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -24,34 +24,34 @@ |
||
| 24 | 24 | class SunsetHeader extends Header |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var DateTimeInterface |
|
| 29 | - */ |
|
| 30 | - private DateTimeInterface $timestamp; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Constructor of the class |
|
| 34 | - * |
|
| 35 | - * @param DateTimeInterface $timestamp |
|
| 36 | - */ |
|
| 37 | - public function __construct(DateTimeInterface $timestamp) |
|
| 38 | - { |
|
| 39 | - $this->timestamp = $timestamp; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * {@inheritdoc} |
|
| 44 | - */ |
|
| 45 | - public function getFieldName(): string |
|
| 46 | - { |
|
| 47 | - return 'Sunset'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * {@inheritdoc} |
|
| 52 | - */ |
|
| 53 | - public function getFieldValue(): string |
|
| 54 | - { |
|
| 55 | - return $this->formatDateTime($this->timestamp); |
|
| 56 | - } |
|
| 27 | + /** |
|
| 28 | + * @var DateTimeInterface |
|
| 29 | + */ |
|
| 30 | + private DateTimeInterface $timestamp; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Constructor of the class |
|
| 34 | + * |
|
| 35 | + * @param DateTimeInterface $timestamp |
|
| 36 | + */ |
|
| 37 | + public function __construct(DateTimeInterface $timestamp) |
|
| 38 | + { |
|
| 39 | + $this->timestamp = $timestamp; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * {@inheritdoc} |
|
| 44 | + */ |
|
| 45 | + public function getFieldName(): string |
|
| 46 | + { |
|
| 47 | + return 'Sunset'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * {@inheritdoc} |
|
| 52 | + */ |
|
| 53 | + public function getFieldValue(): string |
|
| 54 | + { |
|
| 55 | + return $this->formatDateTime($this->timestamp); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -17,11 +17,11 @@ |
||
| 17 | 17 | class ContentSecurityPolicyReportOnlyHeader extends ContentSecurityPolicyHeader |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * {@inheritdoc} |
|
| 22 | - */ |
|
| 23 | - public function getFieldName(): string |
|
| 24 | - { |
|
| 25 | - return 'Content-Security-Policy-Report-Only'; |
|
| 26 | - } |
|
| 20 | + /** |
|
| 21 | + * {@inheritdoc} |
|
| 22 | + */ |
|
| 23 | + public function getFieldName(): string |
|
| 24 | + { |
|
| 25 | + return 'Content-Security-Policy-Report-Only'; |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -22,19 +22,19 @@ |
||
| 22 | 22 | class AccessControlAllowCredentialsHeader extends Header |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * {@inheritdoc} |
|
| 27 | - */ |
|
| 28 | - public function getFieldName(): string |
|
| 29 | - { |
|
| 30 | - return 'Access-Control-Allow-Credentials'; |
|
| 31 | - } |
|
| 25 | + /** |
|
| 26 | + * {@inheritdoc} |
|
| 27 | + */ |
|
| 28 | + public function getFieldName(): string |
|
| 29 | + { |
|
| 30 | + return 'Access-Control-Allow-Credentials'; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * {@inheritdoc} |
|
| 35 | - */ |
|
| 36 | - public function getFieldValue(): string |
|
| 37 | - { |
|
| 38 | - return 'true'; |
|
| 39 | - } |
|
| 33 | + /** |
|
| 34 | + * {@inheritdoc} |
|
| 35 | + */ |
|
| 36 | + public function getFieldValue(): string |
|
| 37 | + { |
|
| 38 | + return 'true'; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -35,354 +35,354 @@ |
||
| 35 | 35 | class ServerRequest extends Request implements ServerRequestInterface |
| 36 | 36 | { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The server parameters |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - private array $serverParams; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * The request's query parameters |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - private array $queryParams; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The request's cookie parameters |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - private array $cookieParams; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * The request's uploaded files |
|
| 61 | - * |
|
| 62 | - * @var array |
|
| 63 | - */ |
|
| 64 | - private array $uploadedFiles; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * The request's parsed body |
|
| 68 | - * |
|
| 69 | - * @var array|object|null |
|
| 70 | - */ |
|
| 71 | - private $parsedBody; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * The request attributes |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - private array $attributes; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Constructor of the class |
|
| 82 | - * |
|
| 83 | - * @param string|null $protocolVersion |
|
| 84 | - * @param string|null $method |
|
| 85 | - * @param mixed $uri |
|
| 86 | - * @param array<string, string|string[]>|null $headers |
|
| 87 | - * @param StreamInterface|null $body |
|
| 88 | - * |
|
| 89 | - * @param array $serverParams |
|
| 90 | - * @param array $queryParams |
|
| 91 | - * @param array $cookieParams |
|
| 92 | - * @param array $uploadedFiles |
|
| 93 | - * @param array|object|null $parsedBody |
|
| 94 | - * @param array $attributes |
|
| 95 | - * |
|
| 96 | - * @throws InvalidArgumentException |
|
| 97 | - * If one of the parameters isn't valid. |
|
| 98 | - */ |
|
| 99 | - public function __construct( |
|
| 100 | - ?string $protocolVersion = null, |
|
| 101 | - ?string $method = null, |
|
| 102 | - $uri = null, |
|
| 103 | - ?array $headers = null, |
|
| 104 | - ?StreamInterface $body = null, |
|
| 105 | - array $serverParams = [], |
|
| 106 | - array $queryParams = [], |
|
| 107 | - array $cookieParams = [], |
|
| 108 | - array $uploadedFiles = [], |
|
| 109 | - $parsedBody = null, |
|
| 110 | - array $attributes = [] |
|
| 111 | - ) { |
|
| 112 | - if (isset($protocolVersion)) { |
|
| 113 | - $this->setProtocolVersion($protocolVersion); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - parent::__construct($method, $uri, $headers, $body); |
|
| 117 | - |
|
| 118 | - $this->serverParams = $serverParams; |
|
| 119 | - $this->queryParams = $queryParams; |
|
| 120 | - $this->cookieParams = $cookieParams; |
|
| 121 | - $this->setUploadedFiles($uploadedFiles); |
|
| 122 | - $this->setParsedBody($parsedBody); |
|
| 123 | - $this->attributes = $attributes; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Gets the server parameters |
|
| 128 | - * |
|
| 129 | - * @return array |
|
| 130 | - */ |
|
| 131 | - public function getServerParams(): array |
|
| 132 | - { |
|
| 133 | - return $this->serverParams; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Gets the request's query parameters |
|
| 138 | - * |
|
| 139 | - * @return array |
|
| 140 | - */ |
|
| 141 | - public function getQueryParams(): array |
|
| 142 | - { |
|
| 143 | - return $this->queryParams; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Creates a new instance of the request with the given query parameters |
|
| 148 | - * |
|
| 149 | - * @param array $query |
|
| 150 | - * |
|
| 151 | - * @return static |
|
| 152 | - */ |
|
| 153 | - public function withQueryParams(array $query): ServerRequestInterface |
|
| 154 | - { |
|
| 155 | - $clone = clone $this; |
|
| 156 | - $clone->queryParams = $query; |
|
| 157 | - |
|
| 158 | - return $clone; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Gets the request's cookie parameters |
|
| 163 | - * |
|
| 164 | - * @return array |
|
| 165 | - */ |
|
| 166 | - public function getCookieParams(): array |
|
| 167 | - { |
|
| 168 | - return $this->cookieParams; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Creates a new instance of the request with the given cookie parameters |
|
| 173 | - * |
|
| 174 | - * @param array $cookies |
|
| 175 | - * |
|
| 176 | - * @return static |
|
| 177 | - */ |
|
| 178 | - public function withCookieParams(array $cookies): ServerRequestInterface |
|
| 179 | - { |
|
| 180 | - $clone = clone $this; |
|
| 181 | - $clone->cookieParams = $cookies; |
|
| 182 | - |
|
| 183 | - return $clone; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Gets the request's uploaded files |
|
| 188 | - * |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - public function getUploadedFiles(): array |
|
| 192 | - { |
|
| 193 | - return $this->uploadedFiles; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Creates a new instance of the request with the given uploaded files |
|
| 198 | - * |
|
| 199 | - * @param array $uploadedFiles |
|
| 200 | - * |
|
| 201 | - * @return static |
|
| 202 | - * |
|
| 203 | - * @throws InvalidArgumentException |
|
| 204 | - * If one of the files isn't valid. |
|
| 205 | - */ |
|
| 206 | - public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface |
|
| 207 | - { |
|
| 208 | - $clone = clone $this; |
|
| 209 | - $clone->setUploadedFiles($uploadedFiles); |
|
| 210 | - |
|
| 211 | - return $clone; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Gets the request's parsed body |
|
| 216 | - * |
|
| 217 | - * @return array|object|null |
|
| 218 | - */ |
|
| 219 | - public function getParsedBody() |
|
| 220 | - { |
|
| 221 | - return $this->parsedBody; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Creates a new instance of the request with the given parsed body |
|
| 226 | - * |
|
| 227 | - * @param array|object|null $data |
|
| 228 | - * |
|
| 229 | - * @return static |
|
| 230 | - * |
|
| 231 | - * @throws InvalidArgumentException |
|
| 232 | - * If the data isn't valid. |
|
| 233 | - */ |
|
| 234 | - public function withParsedBody($data): ServerRequestInterface |
|
| 235 | - { |
|
| 236 | - $clone = clone $this; |
|
| 237 | - $clone->setParsedBody($data); |
|
| 238 | - |
|
| 239 | - return $clone; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Gets the request attributes |
|
| 244 | - * |
|
| 245 | - * @return array |
|
| 246 | - */ |
|
| 247 | - public function getAttributes(): array |
|
| 248 | - { |
|
| 249 | - return $this->attributes; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Gets the request's attribute value by the given name |
|
| 254 | - * |
|
| 255 | - * Returns the default value if the attribute wasn't found. |
|
| 256 | - * |
|
| 257 | - * @param array-key $name |
|
| 258 | - * @param mixed $default |
|
| 259 | - * |
|
| 260 | - * @return mixed |
|
| 261 | - */ |
|
| 262 | - public function getAttribute($name, $default = null) |
|
| 263 | - { |
|
| 264 | - if (!array_key_exists($name, $this->attributes)) { |
|
| 265 | - return $default; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return $this->attributes[$name]; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Creates a new instance of the request with the given attribute |
|
| 273 | - * |
|
| 274 | - * @param array-key $name |
|
| 275 | - * @param mixed $value |
|
| 276 | - * |
|
| 277 | - * @return static |
|
| 278 | - */ |
|
| 279 | - public function withAttribute($name, $value): ServerRequestInterface |
|
| 280 | - { |
|
| 281 | - $clone = clone $this; |
|
| 282 | - $clone->attributes[$name] = $value; |
|
| 283 | - |
|
| 284 | - return $clone; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Creates a new instance of the request without an attribute with the given name |
|
| 289 | - * |
|
| 290 | - * @param array-key $name |
|
| 291 | - * |
|
| 292 | - * @return static |
|
| 293 | - */ |
|
| 294 | - public function withoutAttribute($name): ServerRequestInterface |
|
| 295 | - { |
|
| 296 | - $clone = clone $this; |
|
| 297 | - unset($clone->attributes[$name]); |
|
| 298 | - |
|
| 299 | - return $clone; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Sets the given uploaded files to the request |
|
| 304 | - * |
|
| 305 | - * @param array $files |
|
| 306 | - * |
|
| 307 | - * @return void |
|
| 308 | - * |
|
| 309 | - * @throws InvalidArgumentException |
|
| 310 | - * If one of the files isn't valid. |
|
| 311 | - */ |
|
| 312 | - final protected function setUploadedFiles(array $files): void |
|
| 313 | - { |
|
| 314 | - $this->validateUploadedFiles($files); |
|
| 315 | - |
|
| 316 | - $this->uploadedFiles = $files; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Sets the given parsed body to the request |
|
| 321 | - * |
|
| 322 | - * @param array|object|null $data |
|
| 323 | - * |
|
| 324 | - * @return void |
|
| 325 | - * |
|
| 326 | - * @throws InvalidArgumentException |
|
| 327 | - * If the parsed body isn't valid. |
|
| 328 | - */ |
|
| 329 | - final protected function setParsedBody($data): void |
|
| 330 | - { |
|
| 331 | - $this->validateParsedBody($data); |
|
| 332 | - |
|
| 333 | - $this->parsedBody = $data; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Validates the given uploaded files |
|
| 338 | - * |
|
| 339 | - * @param array $files |
|
| 340 | - * |
|
| 341 | - * @return void |
|
| 342 | - * |
|
| 343 | - * @throws InvalidArgumentException |
|
| 344 | - * If one of the files isn't valid. |
|
| 345 | - */ |
|
| 346 | - private function validateUploadedFiles(array $files): void |
|
| 347 | - { |
|
| 348 | - if ([] === $files) { |
|
| 349 | - return; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @param mixed $file |
|
| 354 | - * |
|
| 355 | - * @return void |
|
| 356 | - * |
|
| 357 | - * @throws InvalidArgumentException |
|
| 358 | - * |
|
| 359 | - * @psalm-suppress MissingClosureParamType |
|
| 360 | - */ |
|
| 361 | - array_walk_recursive($files, static function ($file): void { |
|
| 362 | - if (! ($file instanceof UploadedFileInterface)) { |
|
| 363 | - throw new InvalidArgumentException('Invalid uploaded files'); |
|
| 364 | - } |
|
| 365 | - }); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Validates the given parsed body |
|
| 370 | - * |
|
| 371 | - * @param mixed $data |
|
| 372 | - * |
|
| 373 | - * @return void |
|
| 374 | - * |
|
| 375 | - * @throws InvalidArgumentException |
|
| 376 | - * If the parsed body isn't valid. |
|
| 377 | - */ |
|
| 378 | - private function validateParsedBody($data): void |
|
| 379 | - { |
|
| 380 | - if (null === $data) { |
|
| 381 | - return; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if (!is_array($data) && !is_object($data)) { |
|
| 385 | - throw new InvalidArgumentException('Invalid parsed body'); |
|
| 386 | - } |
|
| 387 | - } |
|
| 38 | + /** |
|
| 39 | + * The server parameters |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + private array $serverParams; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * The request's query parameters |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + private array $queryParams; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The request's cookie parameters |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + private array $cookieParams; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * The request's uploaded files |
|
| 61 | + * |
|
| 62 | + * @var array |
|
| 63 | + */ |
|
| 64 | + private array $uploadedFiles; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * The request's parsed body |
|
| 68 | + * |
|
| 69 | + * @var array|object|null |
|
| 70 | + */ |
|
| 71 | + private $parsedBody; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * The request attributes |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + private array $attributes; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Constructor of the class |
|
| 82 | + * |
|
| 83 | + * @param string|null $protocolVersion |
|
| 84 | + * @param string|null $method |
|
| 85 | + * @param mixed $uri |
|
| 86 | + * @param array<string, string|string[]>|null $headers |
|
| 87 | + * @param StreamInterface|null $body |
|
| 88 | + * |
|
| 89 | + * @param array $serverParams |
|
| 90 | + * @param array $queryParams |
|
| 91 | + * @param array $cookieParams |
|
| 92 | + * @param array $uploadedFiles |
|
| 93 | + * @param array|object|null $parsedBody |
|
| 94 | + * @param array $attributes |
|
| 95 | + * |
|
| 96 | + * @throws InvalidArgumentException |
|
| 97 | + * If one of the parameters isn't valid. |
|
| 98 | + */ |
|
| 99 | + public function __construct( |
|
| 100 | + ?string $protocolVersion = null, |
|
| 101 | + ?string $method = null, |
|
| 102 | + $uri = null, |
|
| 103 | + ?array $headers = null, |
|
| 104 | + ?StreamInterface $body = null, |
|
| 105 | + array $serverParams = [], |
|
| 106 | + array $queryParams = [], |
|
| 107 | + array $cookieParams = [], |
|
| 108 | + array $uploadedFiles = [], |
|
| 109 | + $parsedBody = null, |
|
| 110 | + array $attributes = [] |
|
| 111 | + ) { |
|
| 112 | + if (isset($protocolVersion)) { |
|
| 113 | + $this->setProtocolVersion($protocolVersion); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + parent::__construct($method, $uri, $headers, $body); |
|
| 117 | + |
|
| 118 | + $this->serverParams = $serverParams; |
|
| 119 | + $this->queryParams = $queryParams; |
|
| 120 | + $this->cookieParams = $cookieParams; |
|
| 121 | + $this->setUploadedFiles($uploadedFiles); |
|
| 122 | + $this->setParsedBody($parsedBody); |
|
| 123 | + $this->attributes = $attributes; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Gets the server parameters |
|
| 128 | + * |
|
| 129 | + * @return array |
|
| 130 | + */ |
|
| 131 | + public function getServerParams(): array |
|
| 132 | + { |
|
| 133 | + return $this->serverParams; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Gets the request's query parameters |
|
| 138 | + * |
|
| 139 | + * @return array |
|
| 140 | + */ |
|
| 141 | + public function getQueryParams(): array |
|
| 142 | + { |
|
| 143 | + return $this->queryParams; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Creates a new instance of the request with the given query parameters |
|
| 148 | + * |
|
| 149 | + * @param array $query |
|
| 150 | + * |
|
| 151 | + * @return static |
|
| 152 | + */ |
|
| 153 | + public function withQueryParams(array $query): ServerRequestInterface |
|
| 154 | + { |
|
| 155 | + $clone = clone $this; |
|
| 156 | + $clone->queryParams = $query; |
|
| 157 | + |
|
| 158 | + return $clone; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Gets the request's cookie parameters |
|
| 163 | + * |
|
| 164 | + * @return array |
|
| 165 | + */ |
|
| 166 | + public function getCookieParams(): array |
|
| 167 | + { |
|
| 168 | + return $this->cookieParams; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Creates a new instance of the request with the given cookie parameters |
|
| 173 | + * |
|
| 174 | + * @param array $cookies |
|
| 175 | + * |
|
| 176 | + * @return static |
|
| 177 | + */ |
|
| 178 | + public function withCookieParams(array $cookies): ServerRequestInterface |
|
| 179 | + { |
|
| 180 | + $clone = clone $this; |
|
| 181 | + $clone->cookieParams = $cookies; |
|
| 182 | + |
|
| 183 | + return $clone; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Gets the request's uploaded files |
|
| 188 | + * |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + public function getUploadedFiles(): array |
|
| 192 | + { |
|
| 193 | + return $this->uploadedFiles; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Creates a new instance of the request with the given uploaded files |
|
| 198 | + * |
|
| 199 | + * @param array $uploadedFiles |
|
| 200 | + * |
|
| 201 | + * @return static |
|
| 202 | + * |
|
| 203 | + * @throws InvalidArgumentException |
|
| 204 | + * If one of the files isn't valid. |
|
| 205 | + */ |
|
| 206 | + public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface |
|
| 207 | + { |
|
| 208 | + $clone = clone $this; |
|
| 209 | + $clone->setUploadedFiles($uploadedFiles); |
|
| 210 | + |
|
| 211 | + return $clone; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Gets the request's parsed body |
|
| 216 | + * |
|
| 217 | + * @return array|object|null |
|
| 218 | + */ |
|
| 219 | + public function getParsedBody() |
|
| 220 | + { |
|
| 221 | + return $this->parsedBody; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Creates a new instance of the request with the given parsed body |
|
| 226 | + * |
|
| 227 | + * @param array|object|null $data |
|
| 228 | + * |
|
| 229 | + * @return static |
|
| 230 | + * |
|
| 231 | + * @throws InvalidArgumentException |
|
| 232 | + * If the data isn't valid. |
|
| 233 | + */ |
|
| 234 | + public function withParsedBody($data): ServerRequestInterface |
|
| 235 | + { |
|
| 236 | + $clone = clone $this; |
|
| 237 | + $clone->setParsedBody($data); |
|
| 238 | + |
|
| 239 | + return $clone; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Gets the request attributes |
|
| 244 | + * |
|
| 245 | + * @return array |
|
| 246 | + */ |
|
| 247 | + public function getAttributes(): array |
|
| 248 | + { |
|
| 249 | + return $this->attributes; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Gets the request's attribute value by the given name |
|
| 254 | + * |
|
| 255 | + * Returns the default value if the attribute wasn't found. |
|
| 256 | + * |
|
| 257 | + * @param array-key $name |
|
| 258 | + * @param mixed $default |
|
| 259 | + * |
|
| 260 | + * @return mixed |
|
| 261 | + */ |
|
| 262 | + public function getAttribute($name, $default = null) |
|
| 263 | + { |
|
| 264 | + if (!array_key_exists($name, $this->attributes)) { |
|
| 265 | + return $default; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return $this->attributes[$name]; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Creates a new instance of the request with the given attribute |
|
| 273 | + * |
|
| 274 | + * @param array-key $name |
|
| 275 | + * @param mixed $value |
|
| 276 | + * |
|
| 277 | + * @return static |
|
| 278 | + */ |
|
| 279 | + public function withAttribute($name, $value): ServerRequestInterface |
|
| 280 | + { |
|
| 281 | + $clone = clone $this; |
|
| 282 | + $clone->attributes[$name] = $value; |
|
| 283 | + |
|
| 284 | + return $clone; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Creates a new instance of the request without an attribute with the given name |
|
| 289 | + * |
|
| 290 | + * @param array-key $name |
|
| 291 | + * |
|
| 292 | + * @return static |
|
| 293 | + */ |
|
| 294 | + public function withoutAttribute($name): ServerRequestInterface |
|
| 295 | + { |
|
| 296 | + $clone = clone $this; |
|
| 297 | + unset($clone->attributes[$name]); |
|
| 298 | + |
|
| 299 | + return $clone; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Sets the given uploaded files to the request |
|
| 304 | + * |
|
| 305 | + * @param array $files |
|
| 306 | + * |
|
| 307 | + * @return void |
|
| 308 | + * |
|
| 309 | + * @throws InvalidArgumentException |
|
| 310 | + * If one of the files isn't valid. |
|
| 311 | + */ |
|
| 312 | + final protected function setUploadedFiles(array $files): void |
|
| 313 | + { |
|
| 314 | + $this->validateUploadedFiles($files); |
|
| 315 | + |
|
| 316 | + $this->uploadedFiles = $files; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Sets the given parsed body to the request |
|
| 321 | + * |
|
| 322 | + * @param array|object|null $data |
|
| 323 | + * |
|
| 324 | + * @return void |
|
| 325 | + * |
|
| 326 | + * @throws InvalidArgumentException |
|
| 327 | + * If the parsed body isn't valid. |
|
| 328 | + */ |
|
| 329 | + final protected function setParsedBody($data): void |
|
| 330 | + { |
|
| 331 | + $this->validateParsedBody($data); |
|
| 332 | + |
|
| 333 | + $this->parsedBody = $data; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Validates the given uploaded files |
|
| 338 | + * |
|
| 339 | + * @param array $files |
|
| 340 | + * |
|
| 341 | + * @return void |
|
| 342 | + * |
|
| 343 | + * @throws InvalidArgumentException |
|
| 344 | + * If one of the files isn't valid. |
|
| 345 | + */ |
|
| 346 | + private function validateUploadedFiles(array $files): void |
|
| 347 | + { |
|
| 348 | + if ([] === $files) { |
|
| 349 | + return; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @param mixed $file |
|
| 354 | + * |
|
| 355 | + * @return void |
|
| 356 | + * |
|
| 357 | + * @throws InvalidArgumentException |
|
| 358 | + * |
|
| 359 | + * @psalm-suppress MissingClosureParamType |
|
| 360 | + */ |
|
| 361 | + array_walk_recursive($files, static function ($file): void { |
|
| 362 | + if (! ($file instanceof UploadedFileInterface)) { |
|
| 363 | + throw new InvalidArgumentException('Invalid uploaded files'); |
|
| 364 | + } |
|
| 365 | + }); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Validates the given parsed body |
|
| 370 | + * |
|
| 371 | + * @param mixed $data |
|
| 372 | + * |
|
| 373 | + * @return void |
|
| 374 | + * |
|
| 375 | + * @throws InvalidArgumentException |
|
| 376 | + * If the parsed body isn't valid. |
|
| 377 | + */ |
|
| 378 | + private function validateParsedBody($data): void |
|
| 379 | + { |
|
| 380 | + if (null === $data) { |
|
| 381 | + return; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if (!is_array($data) && !is_object($data)) { |
|
| 385 | + throw new InvalidArgumentException('Invalid parsed body'); |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | 388 | } |
@@ -358,8 +358,8 @@ |
||
| 358 | 358 | * |
| 359 | 359 | * @psalm-suppress MissingClosureParamType |
| 360 | 360 | */ |
| 361 | - array_walk_recursive($files, static function ($file): void { |
|
| 362 | - if (! ($file instanceof UploadedFileInterface)) { |
|
| 361 | + array_walk_recursive($files, static function($file): void { |
|
| 362 | + if (!($file instanceof UploadedFileInterface)) { |
|
| 363 | 363 | throw new InvalidArgumentException('Invalid uploaded files'); |
| 364 | 364 | } |
| 365 | 365 | }); |