diff --git a/CHANGELOG.md b/CHANGELOG.md index 60cf5a6..8749fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## Unreleased +## Added + +- Check for empty string in Stream factories + ## Fixed - FilteredStream::getSize returns null because the contents size is unknown. diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index 21690de..d3bed9d 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -24,10 +24,12 @@ public function createStream($body = null) } else { $stream = new Stream('php://memory', 'rw'); - if (null !== $body) { - $stream->write((string) $body); + if (null === $body || '' === $body) { + return $stream; } + $stream->write((string) $body); + $body = $stream; } } diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index e779f3b..32b9ac7 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -28,9 +28,11 @@ public function createStream($body = null) $resource = fopen('php://memory', 'r+'); $stream = new Stream($resource); - if (null !== $body) { - $stream->write((string) $body); + if (null === $body || '' === $body) { + return $stream; } + + $stream->write((string) $body); } $stream->rewind();