|
11 | 11 |
|
12 | 12 | namespace chillerlan\HTTP\Utils;
|
13 | 13 |
|
14 |
| -use Psr\Http\Message\{ |
15 |
| - ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, |
16 |
| - UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface |
17 |
| -}; |
| 14 | +use Psr\Http\Message\{ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, StreamInterface, |
| 15 | + UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface}; |
18 | 16 | use InvalidArgumentException;
|
19 | 17 | use function array_keys, explode, function_exists, is_array, is_file, substr;
|
20 | 18 |
|
@@ -176,15 +174,22 @@ public function createUploadedFileFromSpec(array $value):UploadedFileInterface|a
|
176 | 174 | return self::normalizeNestedFileSpec($value);
|
177 | 175 | }
|
178 | 176 |
|
179 |
| - // not sure if dumb or genius |
180 |
| - $stream = is_file($value['tmp_name']) |
181 |
| - ? $this->streamFactory->createStreamFromFile($value['tmp_name']) |
182 |
| - : $this->streamFactory->createStream($value['tmp_name']); // @codeCoverageIgnore |
| 177 | + $stream = $this->createStreamFromFile($value['tmp_name']); |
183 | 178 |
|
184 | 179 | return $this->uploadedFileFactory
|
185 | 180 | ->createUploadedFile($stream, (int)$value['size'], (int)$value['error'], $value['name'], $value['type']);
|
186 | 181 | }
|
187 | 182 |
|
| 183 | + /** @codeCoverageIgnore */ |
| 184 | + private function createStreamFromFile(string $file):StreamInterface{ |
| 185 | + |
| 186 | + if(is_file($file)){ |
| 187 | + return $this->streamFactory->createStreamFromFile($file); |
| 188 | + } |
| 189 | + |
| 190 | + return $this->streamFactory->createStream($file); |
| 191 | + } |
| 192 | + |
188 | 193 | /**
|
189 | 194 | * Normalizes an array of file specifications.
|
190 | 195 | *
|
|
0 commit comments