diff options
Diffstat (limited to 'src/Diactoros/StreamFactory.php')
-rw-r--r-- | src/Diactoros/StreamFactory.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/Diactoros/StreamFactory.php b/src/Diactoros/StreamFactory.php new file mode 100644 index 00000000..6004ef11 --- /dev/null +++ b/src/Diactoros/StreamFactory.php @@ -0,0 +1,45 @@ +<?php +declare(strict_types=1); + +/** + * High-performance PHP process supervisor and load balancer written in Go + * + * @author Wolfy-J + */ + +namespace Spiral\RoadRunner\Diactoros; + +use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\StreamInterface; +use Zend\Diactoros\Stream; + +final class StreamFactory implements StreamFactoryInterface +{ + /** + * @inheritdoc + */ + public function createStream(string $content = ''): StreamInterface + { + $resource = fopen('php://temp', 'r+'); + fwrite($resource, $content); + rewind($resource); + return $this->createStreamFromResource($resource); + } + + /** + * @inheritdoc + */ + public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface + { + $resource = fopen($file, $mode); + return $this->createStreamFromResource($resource); + } + + /** + * @inheritdoc + */ + public function createStreamFromResource($resource): StreamInterface + { + return new Stream($resource); + } +}
\ No newline at end of file |