← All changes
|
includes/sdk/s3/GuzzleHttp/Psr7/ServerRequest.php
+28
-68
1.2.10
→
1.4.2
View file →
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +declare (strict_types=1); | |
| 3 | 4 | namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7; |
| 4 | 5 | |
| 5 | 6 | use InvalidArgumentException; |
| 6 | 7 | use Dudlewebs\WPMCS\s3\Psr\Http\Message\ServerRequestInterface; |
| @@ -49,14 +50,14 @@ | ||
| 49 | 50 | private $uploadedFiles = []; |
| 50 | 51 | /** |
| 51 | 52 | * @param string $method HTTP method |
| 52 | 53 | * @param string|UriInterface $uri URI |
| 53 | - * @param array $headers Request headers | |
| 54 | + * @param (string|string[])[] $headers Request headers | |
| 54 | 55 | * @param string|resource|StreamInterface|null $body Request body |
| 55 | 56 | * @param string $version Protocol version |
| 56 | 57 | * @param array $serverParams Typically the $_SERVER superglobal |
| 57 | 58 | */ |
| 58 | - public function __construct($method, $uri, array $headers = [], $body = null, $version = '1.1', array $serverParams = []) | |
| 59 | + public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1', array $serverParams = []) | |
| 59 | 60 | { |
| 60 | 61 | $this->serverParams = $serverParams; |
| 61 | 62 | parent::__construct($method, $uri, $headers, $body, $version); |
| 62 | 63 | } |
| @@ -62,15 +63,13 @@ | ||
| 62 | 63 | } |
| 63 | 64 | /** |
| 64 | 65 | * Return an UploadedFile instance array. |
| 65 | 66 | * |
| 66 | - * @param array $files A array which respect $_FILES structure | |
| 67 | + * @param array $files An array which respect $_FILES structure | |
| 67 | 68 | * |
| 68 | - * @return array | |
| 69 | - * | |
| 70 | 69 | * @throws InvalidArgumentException for unrecognized values |
| 71 | 70 | */ |
| 72 | - public static function normalizeFiles(array $files) | |
| 71 | + public static function normalizeFiles(array $files) : array | |
| 73 | 72 | { |
| 74 | 73 | $normalized = []; |
| 75 | 74 | foreach ($files as $key => $value) { |
| 76 | 75 | if ($value instanceof UploadedFileInterface) { |
| @@ -93,9 +92,9 @@ | ||
| 93 | 92 | * delegate to normalizeNestedFileSpec() and return that return value. |
| 94 | 93 | * |
| 95 | 94 | * @param array $value $_FILES struct |
| 96 | 95 | * |
| 97 | - * @return array|UploadedFileInterface | |
| 96 | + * @return UploadedFileInterface|UploadedFileInterface[] | |
| 98 | 97 | */ |
| 99 | 98 | private static function createUploadedFileFromSpec(array $value) |
| 100 | 99 | { |
| 101 | 100 | if (\is_array($value['tmp_name'])) { |
| @@ -108,17 +107,15 @@ | ||
| 108 | 107 | * |
| 109 | 108 | * Loops through all nested files and returns a normalized array of |
| 110 | 109 | * UploadedFileInterface instances. |
| 111 | 110 | * |
| 112 | - * @param array $files | |
| 113 | - * | |
| 114 | 111 | * @return UploadedFileInterface[] |
| 115 | 112 | */ |
| 116 | - private static function normalizeNestedFileSpec(array $files = []) | |
| 113 | + private static function normalizeNestedFileSpec(array $files = []) : array | |
| 117 | 114 | { |
| 118 | 115 | $normalizedFiles = []; |
| 119 | 116 | foreach (\array_keys($files['tmp_name']) as $key) { |
| 120 | - $spec = ['tmp_name' => $files['tmp_name'][$key], 'size' => $files['size'][$key], 'error' => $files['error'][$key], 'name' => $files['name'][$key], 'type' => $files['type'][$key]]; | |
| 117 | + $spec = ['tmp_name' => $files['tmp_name'][$key], 'size' => $files['size'][$key] ?? null, 'error' => $files['error'][$key] ?? null, 'name' => $files['name'][$key] ?? null, 'type' => $files['type'][$key] ?? null]; | |
| 121 | 118 | $normalizedFiles[$key] = self::createUploadedFileFromSpec($spec); |
| 122 | 119 | } |
| 123 | 120 | return $normalizedFiles; |
| 124 | 121 | } |
| @@ -128,14 +125,12 @@ | ||
| 128 | 125 | * $_POST |
| 129 | 126 | * $_COOKIE |
| 130 | 127 | * $_FILES |
| 131 | 128 | * $_SERVER |
| 132 | - * | |
| 133 | - * @return ServerRequestInterface | |
| 134 | 129 | */ |
| 135 | - public static function fromGlobals() | |
| 130 | + public static function fromGlobals() : ServerRequestInterface | |
| 136 | 131 | { |
| 137 | - $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; | |
| 132 | + $method = $_SERVER['REQUEST_METHOD'] ?? 'GET'; | |
| 138 | 133 | $headers = \getallheaders(); |
| 139 | 134 | $uri = self::getUriFromGlobals(); |
| 140 | 135 | $body = new CachingStream(new LazyOpenStream('php://input', 'r+')); |
| 141 | 136 | $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? \str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1'; |
| @@ -141,9 +136,9 @@ | ||
| 141 | 136 | $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? \str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1'; |
| 142 | 137 | $serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER); |
| 143 | 138 | return $serverRequest->withCookieParams($_COOKIE)->withQueryParams($_GET)->withParsedBody($_POST)->withUploadedFiles(self::normalizeFiles($_FILES)); |
| 144 | 139 | } |
| 145 | - private static function extractHostAndPortFromAuthority($authority) | |
| 140 | + private static function extractHostAndPortFromAuthority(string $authority) : array | |
| 146 | 141 | { |
| 147 | 142 | $uri = 'http://' . $authority; |
| 148 | 143 | $parts = \parse_url($uri); |
| 149 | 144 | if (\false === $parts) { |
| @@ -148,24 +143,22 @@ | ||
| 148 | 143 | $parts = \parse_url($uri); |
| 149 | 144 | if (\false === $parts) { |
| 150 | 145 | return [null, null]; |
| 151 | 146 | } |
| 152 | - $host = isset($parts['host']) ? $parts['host'] : null; | |
| 153 | - $port = isset($parts['port']) ? $parts['port'] : null; | |
| 147 | + $host = $parts['host'] ?? null; | |
| 148 | + $port = $parts['port'] ?? null; | |
| 154 | 149 | return [$host, $port]; |
| 155 | 150 | } |
| 156 | 151 | /** |
| 157 | 152 | * Get a Uri populated with values from $_SERVER. |
| 158 | - * | |
| 159 | - * @return UriInterface | |
| 160 | 153 | */ |
| 161 | - public static function getUriFromGlobals() | |
| 154 | + public static function getUriFromGlobals() : UriInterface | |
| 162 | 155 | { |
| 163 | 156 | $uri = new Uri(''); |
| 164 | 157 | $uri = $uri->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'); |
| 165 | 158 | $hasPort = \false; |
| 166 | 159 | if (isset($_SERVER['HTTP_HOST'])) { |
| 167 | - list($host, $port) = self::extractHostAndPortFromAuthority($_SERVER['HTTP_HOST']); | |
| 160 | + [$host, $port] = self::extractHostAndPortFromAuthority($_SERVER['HTTP_HOST']); | |
| 168 | 161 | if ($host !== null) { |
| 169 | 162 | $uri = $uri->withHost($host); |
| 170 | 163 | } |
| 171 | 164 | if ($port !== null) { |
| @@ -193,58 +186,37 @@ | ||
| 193 | 186 | $uri = $uri->withQuery($_SERVER['QUERY_STRING']); |
| 194 | 187 | } |
| 195 | 188 | return $uri; |
| 196 | 189 | } |
| 197 | - /** | |
| 198 | - * {@inheritdoc} | |
| 199 | - */ | |
| 200 | - public function getServerParams() | |
| 190 | + public function getServerParams() : array | |
| 201 | 191 | { |
| 202 | 192 | return $this->serverParams; |
| 203 | 193 | } |
| 204 | - /** | |
| 205 | - * {@inheritdoc} | |
| 206 | - */ | |
| 207 | - public function getUploadedFiles() | |
| 194 | + public function getUploadedFiles() : array | |
| 208 | 195 | { |
| 209 | 196 | return $this->uploadedFiles; |
| 210 | 197 | } |
| 211 | - /** | |
| 212 | - * {@inheritdoc} | |
| 213 | - */ | |
| 214 | - public function withUploadedFiles(array $uploadedFiles) | |
| 198 | + public function withUploadedFiles(array $uploadedFiles) : ServerRequestInterface | |
| 215 | 199 | { |
| 216 | 200 | $new = clone $this; |
| 217 | 201 | $new->uploadedFiles = $uploadedFiles; |
| 218 | 202 | return $new; |
| 219 | 203 | } |
| 220 | - /** | |
| 221 | - * {@inheritdoc} | |
| 222 | - */ | |
| 223 | - public function getCookieParams() | |
| 204 | + public function getCookieParams() : array | |
| 224 | 205 | { |
| 225 | 206 | return $this->cookieParams; |
| 226 | 207 | } |
| 227 | - /** | |
| 228 | - * {@inheritdoc} | |
| 229 | - */ | |
| 230 | - public function withCookieParams(array $cookies) | |
| 208 | + public function withCookieParams(array $cookies) : ServerRequestInterface | |
| 231 | 209 | { |
| 232 | 210 | $new = clone $this; |
| 233 | 211 | $new->cookieParams = $cookies; |
| 234 | 212 | return $new; |
| 235 | 213 | } |
| 236 | - /** | |
| 237 | - * {@inheritdoc} | |
| 238 | - */ | |
| 239 | - public function getQueryParams() | |
| 214 | + public function getQueryParams() : array | |
| 240 | 215 | { |
| 241 | 216 | return $this->queryParams; |
| 242 | 217 | } |
| 243 | - /** | |
| 244 | - * {@inheritdoc} | |
| 245 | - */ | |
| 246 | - public function withQueryParams(array $query) | |
| 218 | + public function withQueryParams(array $query) : ServerRequestInterface | |
| 247 | 219 | { |
| 248 | 220 | $new = clone $this; |
| 249 | 221 | $new->queryParams = $query; |
| 250 | 222 | return $new; |
| @@ -249,32 +221,26 @@ | ||
| 249 | 221 | $new->queryParams = $query; |
| 250 | 222 | return $new; |
| 251 | 223 | } |
| 252 | 224 | /** |
| 253 | - * {@inheritdoc} | |
| 225 | + * @return array|object|null | |
| 254 | 226 | */ |
| 255 | 227 | public function getParsedBody() |
| 256 | 228 | { |
| 257 | 229 | return $this->parsedBody; |
| 258 | 230 | } |
| 259 | - /** | |
| 260 | - * {@inheritdoc} | |
| 261 | - */ | |
| 262 | - public function withParsedBody($data) | |
| 231 | + public function withParsedBody($data) : ServerRequestInterface | |
| 263 | 232 | { |
| 264 | 233 | $new = clone $this; |
| 265 | 234 | $new->parsedBody = $data; |
| 266 | 235 | return $new; |
| 267 | 236 | } |
| 268 | - /** | |
| 269 | - * {@inheritdoc} | |
| 270 | - */ | |
| 271 | - public function getAttributes() | |
| 237 | + public function getAttributes() : array | |
| 272 | 238 | { |
| 273 | 239 | return $this->attributes; |
| 274 | 240 | } |
| 275 | 241 | /** |
| 276 | - * {@inheritdoc} | |
| 242 | + * @return mixed | |
| 277 | 243 | */ |
| 278 | 244 | public function getAttribute($attribute, $default = null) |
| 279 | 245 | { |
| 280 | 246 | if (\false === \array_key_exists($attribute, $this->attributes)) { |
| @@ -281,21 +247,15 @@ | ||
| 281 | 247 | return $default; |
| 282 | 248 | } |
| 283 | 249 | return $this->attributes[$attribute]; |
| 284 | 250 | } |
| 285 | - /** | |
| 286 | - * {@inheritdoc} | |
| 287 | - */ | |
| 288 | - public function withAttribute($attribute, $value) | |
| 251 | + public function withAttribute($attribute, $value) : ServerRequestInterface | |
| 289 | 252 | { |
| 290 | 253 | $new = clone $this; |
| 291 | 254 | $new->attributes[$attribute] = $value; |
| 292 | 255 | return $new; |
| 293 | 256 | } |
| 294 | - /** | |
| 295 | - * {@inheritdoc} | |
| 296 | - */ | |
| 297 | - public function withoutAttribute($attribute) | |
| 257 | + public function withoutAttribute($attribute) : ServerRequestInterface | |
| 298 | 258 | { |
| 299 | 259 | if (\false === \array_key_exists($attribute, $this->attributes)) { |
| 300 | 260 | return $this; |
| 301 | 261 | } |