StreamFactory

Class
Read only: Yes Final: Yes

Class StreamFactory.

Description

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.

Table of Contents

Interfaces

StreamFactoryInterface

Interface StreamFactoryInterface.

Properties

 : StreamFactoryInterface

Methods

__construct()

Constructs the StreamFactory instance.

 : mixed
createStream()

Creates a new stream containing the provided string content.

 : StreamInterface
createStreamFromFile()

Creates a new stream from the specified file.

 : StreamInterface
createStreamFromPayload()

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

 : PayloadStreamInterface
createStreamFromResource()

Creates a new stream from the provided PHP resource.

 : StreamInterface
Properties

$streamFactory

Private
private StreamFactoryInterface $streamFactory
Methods

__construct()

Public

Constructs the StreamFactory instance.

public __construct(StreamFactoryInterface  $streamFactory) : mixed
Parameters
$streamFactory : StreamFactoryInterface

Description

the underlying PSR-17 stream factory implementation

createStream()

Public

Creates a new stream containing the provided string content.

public createStream([ string  $content = '']) : StreamInterface
Parameters
$content : string = ''

Description

the string content for the stream

Return values
StreamInterface

Description

the generated stream

createStreamFromFile()

Public

Creates a new stream from the specified file.

public createStreamFromFile( string  $filename[, string  $mode = 'r']) : StreamInterface

Description

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

Parameters
$filename : string

Description

the path to the file to open as a stream

$mode : string = 'r'

Description

The file open mode. Defaults to 'r' (read mode).

Return values
StreamInterface

Description

the generated stream

createStreamFromPayload()

Public

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

public createStreamFromPayload( array<string|int, mixed>  $payload) : PayloadStreamInterface

Description

The returned stream implements PayloadStreamInterface and contains the encoded payload.

Parameters
$payload : array<string|int, mixed>

Description

the payload to encode as JSON

Return values
PayloadStreamInterface

Description

the generated payload stream

createStreamFromResource()

Public

Creates a new stream from the provided PHP resource.

public createStreamFromResource( resource  $resource) : StreamInterface
Parameters
$resource : resource

Description

the PHP resource to wrap as a stream

Return values
StreamInterface

Description

the generated stream