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.
Interfaces
Properties
Methods
Constructs the StreamFactory instance.
Creates a new stream containing the provided string content.
Creates a new stream from the specified file.
Creates a new stream containing the JSON-encoded representation of the provided payload.
Creates a new stream from the provided PHP resource.
Constructs the StreamFactory instance.
public
__construct(StreamFactoryInterface
$streamFactory) : mixed
Parameters
$streamFactory
:
StreamFactoryInterface
Description
the underlying PSR-17 stream factory implementation
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
Description
the generated stream
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
Description
the generated stream
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
Description
the generated payload stream
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
Description
the generated stream