diff options
Diffstat (limited to 'src/Diactoros')
-rw-r--r-- | src/Diactoros/StreamFactory.php | 16 | ||||
-rw-r--r-- | src/Diactoros/UploadedFileFactory.php | 3 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/Diactoros/StreamFactory.php b/src/Diactoros/StreamFactory.php index da0d52ec..cc0a5306 100644 --- a/src/Diactoros/StreamFactory.php +++ b/src/Diactoros/StreamFactory.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace Spiral\RoadRunner\Diactoros; +use RuntimeException; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\StreamInterface; use Zend\Diactoros\Stream; @@ -17,10 +18,16 @@ final class StreamFactory implements StreamFactoryInterface { /** * @inheritdoc + * @throws RuntimeException */ public function createStream(string $content = ''): StreamInterface { - $resource = fopen('php://temp', 'r+'); + $resource = fopen('php://temp', 'rb+'); + + if (! \is_resource($resource)) { + throw new RuntimeException('Cannot create stream'); + } + fwrite($resource, $content); rewind($resource); return $this->createStreamFromResource($resource); @@ -29,9 +36,14 @@ final class StreamFactory implements StreamFactoryInterface /** * @inheritdoc */ - public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface + public function createStreamFromFile(string $file, string $mode = 'rb'): StreamInterface { $resource = fopen($file, $mode); + + if (! \is_resource($resource)) { + throw new RuntimeException('Cannot create stream'); + } + return $this->createStreamFromResource($resource); } diff --git a/src/Diactoros/UploadedFileFactory.php b/src/Diactoros/UploadedFileFactory.php index 4f09fb23..45773287 100644 --- a/src/Diactoros/UploadedFileFactory.php +++ b/src/Diactoros/UploadedFileFactory.php @@ -27,9 +27,10 @@ final class UploadedFileFactory implements UploadedFileFactoryInterface string $clientMediaType = null ): UploadedFileInterface { if ($size === null) { - $size = $stream->getSize(); + $size = (int) $stream->getSize(); } + /** @var resource $stream */ return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); } } |