Class StreamFactory
Factory class for creating stream instances.
Namespace: Cake\Http
Method Summary
-
createStream() public
Create a new stream from a string.
-
createStreamFromFile() public
Create a stream from an existing file.
-
createStreamFromResource() public
Create a new stream from an existing resource.
Method Detail
createStream() ¶ public
createStream(string $content = ''): StreamInterface
Create a new stream from a string.
The stream SHOULD be created with a temporary resource.
Parameters
-
string
$content optional String content with which to populate the stream.
Returns
StreamInterface
createStreamFromFile() ¶ public
createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
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 optional The mode with which to open the underlying filename/stream.
Returns
StreamInterface
Throws
RuntimeException
If the file cannot be opened.
InvalidArgumentException
If the mode is invalid.
createStreamFromResource() ¶ public
createStreamFromResource(resource $resource): StreamInterface
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.
Returns
StreamInterface