# Class HttpSoft\Stream\StreamFactory

Factory for creating HttpSoft\Stream\Stream and HttpSoft\Stream\StreamPhpInput, implements Psr\Http\Message\StreamFactoryInterface.

Source code on GitHub.

use HttpSoft\Stream\StreamFactory;

$factory = new StreamFactory();

// Create `HttpSoft\Stream\StreamPhpInput` instance.

$stream = StreamFactory::create('php://input');
$stream->getMetadata('uri'); // 'php://input'
$stream->getContents(); // ''

// Create `HttpSoft\Stream\Stream` instance.

$stream = StreamFactory::create('php://temp', 'wb+');
$stream->getMetadata('uri'); // 'php://temp'
$stream->getContents(); // ''

// Create `HttpSoft\Stream\Stream` instance from an existing file.

$stream = StreamFactory::create('path/to/file', 'r');
// equivalently to:
$stream = $factory->createStreamFromFile('path/to/file', 'r');

$stream->getMetadata('uri'); // 'path/to/file'
$stream->getContents(); // 'File content'

// Create `HttpSoft\Stream\Stream` instance from an existing resource.

$resource = fopen('path/to/file', 'r');

$stream = StreamFactory::create($resource);
// equivalently to:
$stream = $factory->createStreamFromResource($resource);

$stream->getMetadata('uri'); // 'path/to/file'
$stream->getContents(); // 'File content'

// Create `HttpSoft\Stream\Stream` instance from a string usage a temporary resource.

$stream = StreamFactory::createFromContent('Content');
// equivalently to:
$stream = $factory->createStream('Content');

$stream->getMetadata('uri'); // 'php://temp'
$stream->getContents(); // 'Content'

# Public methods

See the original detailed description of the methods in the Psr\Http\Message\StreamFactoryInterface.

# create

Create a new HttpSoft\Stream\Stream or HttpSoft\Stream\StreamPhpInput instance (static method).

/**
 * @param StreamInterface|string|resource $stream
 * @param string $mode
 * @return StreamInterface
 */
public static function create($stream, string $mode = 'wb+'): StreamInterface;

# createFromContent

Create a new HttpSoft\Stream\Stream instance from a string usage a temporary resource (static method).

public static function createFromContent(string $content = ''): StreamInterface;

# createStream

Create a new HttpSoft\Stream\Stream instance from a string usage a temporary resource.

public function createStream(string $content = ''): StreamInterface;

# createStreamFromFile

Create a new HttpSoft\Stream\Stream instance from an existing file.

public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface;

# createStreamFromResource

Create a new HttpSoft\Stream\Stream instance from an existing resource.

/**
 * @param resource $resource
 * @return StreamInterface
 */
public function createStreamFromResource($resource): StreamInterface;