Skip to content

Commit

Permalink
🚿
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Jul 26, 2024
1 parent 9a7f193 commit 56530b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/ServerUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/UriUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 56530b1

Please sign in to comment.