| @@ 14-36 (lines=23) @@ | ||
| 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 | return $body; |
|
| 23 | } |
|
| 24 | ||
| 25 | if (is_resource($body)) { |
|
| 26 | return new Stream($body); |
|
| 27 | } |
|
| 28 | ||
| 29 | $stream = new Stream('php://memory', 'rw'); |
|
| 30 | if (null !== $body && '' !== $body) { |
|
| 31 | $stream->write((string) $body); |
|
| 32 | } |
|
| 33 | ||
| 34 | return $stream; |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| @@ 14-37 (lines=24) @@ | ||
| 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 | return new Stream($body); |
|
| 27 | } |
|
| 28 | ||
| 29 | $resource = fopen('php://memory', 'r+'); |
|
| 30 | $stream = new Stream($resource); |
|
| 31 | if (null !== $body && '' !== $body) { |
|
| 32 | $stream->write((string) $body); |
|
| 33 | } |
|
| 34 | ||
| 35 | return $stream; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||