for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
/**
* It's free open-source software released under the MIT License.
*
* @author Anatoly Nekhay <[email protected]>
* @copyright Copyright (c) 2018, Anatoly Nekhay
* @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
* @link https://github.com/sunrise-php/http-message
*/
namespace Sunrise\Http\Message;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
use Sunrise\Http\Message\Stream\FileStream;
use Sunrise\Http\Message\Stream\PhpTempStream;
* @psalm-suppress ClassMustBeFinal
class StreamFactory implements StreamFactoryInterface
{
* @inheritDoc
public function createStream(string $content = ''): StreamInterface
$stream = new PhpTempStream();
if ($content === '') {
return $stream;
}
$stream->write($content);
$stream->rewind();
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
return new FileStream($filename, $mode);
public function createStreamFromResource($resource): StreamInterface
return new Stream($resource);