Skip to content

Commit

Permalink
Merge pull request #70 from php-http/empty_stream_body
Browse files Browse the repository at this point in the history
Add check for empty string to stream factories
  • Loading branch information
dbu committed Jan 8, 2017
2 parents f28c46e + e9c1041 commit 016359f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,10 @@

## Unreleased

## Added

- Check for empty string in Stream factories

## Fixed

- FilteredStream::getSize returns null because the contents size is unknown.
Expand Down
6 changes: 4 additions & 2 deletions src/StreamFactory/DiactorosStreamFactory.php
Expand Up @@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/StreamFactory/SlimStreamFactory.php
Expand Up @@ -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();
Expand Down

0 comments on commit 016359f

Please sign in to comment.