Skip to content

Commit 016359f

Browse files
authored
Merge pull request #70 from php-http/empty_stream_body
Add check for empty string to stream factories
2 parents f28c46e + e9c1041 commit 016359f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
## Unreleased
55

6+
## Added
7+
8+
- Check for empty string in Stream factories
9+
610
## Fixed
711

812
- FilteredStream::getSize returns null because the contents size is unknown.

src/StreamFactory/DiactorosStreamFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ public function createStream($body = null)
2424
} else {
2525
$stream = new Stream('php://memory', 'rw');
2626

27-
if (null !== $body) {
28-
$stream->write((string) $body);
27+
if (null === $body || '' === $body) {
28+
return $stream;
2929
}
3030

31+
$stream->write((string) $body);
32+
3133
$body = $stream;
3234
}
3335
}

src/StreamFactory/SlimStreamFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public function createStream($body = null)
2828
$resource = fopen('php://memory', 'r+');
2929
$stream = new Stream($resource);
3030

31-
if (null !== $body) {
32-
$stream->write((string) $body);
31+
if (null === $body || '' === $body) {
32+
return $stream;
3333
}
34+
35+
$stream->write((string) $body);
3436
}
3537

3638
$stream->rewind();

0 commit comments

Comments
 (0)