@@ 14-41 (lines=28) @@ | ||
11 | * |
|
12 | * @author Михаил Красильников <[email protected]> |
|
13 | */ |
|
14 | final class DiactorosStreamFactory implements StreamFactory |
|
15 | { |
|
16 | /** |
|
17 | * {@inheritdoc} |
|
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 || '' === $body) { |
|
28 | return $stream; |
|
29 | } |
|
30 | ||
31 | $stream->write((string) $body); |
|
32 | ||
33 | $body = $stream; |
|
34 | } |
|
35 | } |
|
36 | ||
37 | $body->rewind(); |
|
38 | ||
39 | return $body; |
|
40 | } |
|
41 | } |
|
42 |
@@ 14-42 (lines=29) @@ | ||
11 | * |
|
12 | * @author Mika Tuupola <[email protected]> |
|
13 | */ |
|
14 | final class SlimStreamFactory implements StreamFactory |
|
15 | { |
|
16 | /** |
|
17 | * {@inheritdoc} |
|
18 | */ |
|
19 | public function createStream($body = null) |
|
20 | { |
|
21 | if ($body instanceof StreamInterface) { |
|
22 | return $body; |
|
23 | } |
|
24 | ||
25 | if (is_resource($body)) { |
|
26 | $stream = new Stream($body); |
|
27 | } else { |
|
28 | $resource = fopen('php://memory', 'r+'); |
|
29 | $stream = new Stream($resource); |
|
30 | ||
31 | if (null === $body || '' === $body) { |
|
32 | return $stream; |
|
33 | } |
|
34 | ||
35 | $stream->write((string) $body); |
|
36 | } |
|
37 | ||
38 | $stream->rewind(); |
|
39 | ||
40 | return $stream; |
|
41 | } |
|
42 | } |
|
43 |