From 56530b1773dba7593cd9aa9d28bf4a53ab8d44d8 Mon Sep 17 00:00:00 2001 From: smiley Date: Fri, 26 Jul 2024 18:04:07 +0200 Subject: [PATCH] :shower: --- src/ServerUtil.php | 21 +++++++++++++-------- src/UriUtil.php | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ServerUtil.php b/src/ServerUtil.php index 4a4c97e..17b63e5 100644 --- a/src/ServerUtil.php +++ b/src/ServerUtil.php @@ -11,10 +11,8 @@ namespace chillerlan\HTTP\Utils; -use Psr\Http\Message\{ - ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, - UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface -}; +use Psr\Http\Message\{ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, StreamInterface, + UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface}; use InvalidArgumentException; use function array_keys, explode, function_exists, is_array, is_file, substr; @@ -176,15 +174,22 @@ public function createUploadedFileFromSpec(array $value):UploadedFileInterface|a return self::normalizeNestedFileSpec($value); } - // not sure if dumb or genius - $stream = is_file($value['tmp_name']) - ? $this->streamFactory->createStreamFromFile($value['tmp_name']) - : $this->streamFactory->createStream($value['tmp_name']); // @codeCoverageIgnore + $stream = $this->createStreamFromFile($value['tmp_name']); return $this->uploadedFileFactory ->createUploadedFile($stream, (int)$value['size'], (int)$value['error'], $value['name'], $value['type']); } + /** @codeCoverageIgnore */ + private function createStreamFromFile(string $file):StreamInterface{ + + if(is_file($file)){ + return $this->streamFactory->createStreamFromFile($file); + } + + return $this->streamFactory->createStream($file); + } + /** * Normalizes an array of file specifications. * diff --git a/src/UriUtil.php b/src/UriUtil.php index 32bd807..2f4bebd 100644 --- a/src/UriUtil.php +++ b/src/UriUtil.php @@ -131,7 +131,7 @@ public static function withQueryValue(UriInterface $uri, string $key, string|nul $replaceQuery = ['=' => '%3D', '&' => '%26']; $key = strtr($key, $replaceQuery); - $result[] = $value !== null + $result[] = ($value !== null) ? $key.'='.strtr($value, $replaceQuery) : $key;