class StreamFactory (View source)

Has the ability to create streams for requests and responses.

Methods

StreamInterface
createStream(string $content = '')

Create a new stream from a string.

StreamInterface
createStreamFromFile(string $filename, string $mode = 'r')

Create a stream from an existing file.

StreamInterface
createStreamFromResource(resource $resource)

Create a new stream from an existing resource.

Details

StreamInterface createStream(string $content = '')

Create a new stream from a string.

The stream SHOULD be created with a temporary resource.

Parameters

string $content String content with which to populate the stream.

Return Value

StreamInterface

StreamInterface createStreamFromFile(string $filename, string $mode = 'r')

Create a stream from an existing file.

The file MUST be opened using the given mode, which may be any mode supported by the fopen function.

The $filename MAY be any string supported by fopen().

Parameters

string $filename The filename or stream URI to use as basis of stream.
string $mode The mode with which to open the underlying filename/stream.

Return Value

StreamInterface

Exceptions

RuntimeException If the file cannot be opened.
InvalidArgumentException If the mode is invalid.

StreamInterface createStreamFromResource(resource $resource)

Create a new stream from an existing resource.

The stream MUST be readable and may be writable.

Parameters

resource $resource The PHP resource to use as the basis for the stream.

Return Value

StreamInterface