1 <?php
2
3 namespace Http\Message\StreamFactory;
4
5 use Http\Message\StreamFactory;
6 use Psr\Http\Message\StreamInterface;
7 use Zend\Diactoros\Stream;
8
9 10 11 12 13
14 final class DiactorosStreamFactory implements StreamFactory
15 {
16 17 18
19 public function createStream($body = null)
20 {
21 if (!$body instanceof StreamInterface) {
22 if (is_resource($body)) {
23 $body = new Stream($body);
24 } else {
25 $stream = new Stream('php://memory', 'rw');
26
27 if (null !== $body) {
28 $stream->write((string) $body);
29 }
30
31 $body = $stream;
32 }
33 }
34
35 $body->rewind();
36
37 return $body;
38 }
39 }
40