Skip to content

StreamFactory

github-actions edited this page Mar 29, 2026 · 1 revision

Class StreamFactory.

Decorates a PSR-17 StreamFactoryInterface to provide additional functionality for creating payload streams. Implements both standard PSR-17 stream creation methods and convenient payload-aware stream generation.


Methods

__construct

Constructs the StreamFactory instance.

public __construct(\Psr\Http\Message\StreamFactoryInterface $streamFactory): mixed

Parameters:

Parameter Type Description
$streamFactory \Psr\Http\Message\StreamFactoryInterface the underlying PSR-17 stream factory implementation

createStream

Creates a new stream containing the provided string content.

public createStream(string $content = ''): \Psr\Http\Message\StreamInterface

Parameters:

Parameter Type Description
$content string the string content for the stream

Return Value:

the generated stream


createStreamFromFile

Creates a new stream from the specified file.

public createStreamFromFile(string $filename, string $mode = 'r'): \Psr\Http\Message\StreamInterface

The file is opened with the given mode, and a stream is returned.

Parameters:

Parameter Type Description
$filename string the path to the file to open as a stream
$mode string The file open mode. Defaults to 'r' (read mode).

Return Value:

the generated stream


createStreamFromResource

Creates a new stream from the provided PHP resource.

public createStreamFromResource(resource $resource): \Psr\Http\Message\StreamInterface

Parameters:

Parameter Type Description
$resource resource the PHP resource to wrap as a stream

Return Value:

the generated stream


createStreamFromPayload

Creates a new stream containing the JSON-encoded representation of the provided payload.

public createStreamFromPayload(array $payload): \FastForward\Http\Message\PayloadStreamInterface

The returned stream implements PayloadStreamInterface and contains the encoded payload.

Parameters:

Parameter Type Description
$payload array the payload to encode as JSON

Return Value:

the generated payload stream


Clone this wiki locally