ContentStream
class ContentStream implements StreamInterface (View source)
Implementation of a PSR-7 HTTP stream
Properties
protected resource | $resource | ||
protected string|resource | $stream | ||
protected LoggerInterface | $logger |
Methods
No description
Creates an instance representing the given $contents string
Closes the stream and any underlying resources.
Separates any underlying resources from the stream.
Attach a new stream/resource to the instance.
Get the size of the stream if known.
Returns the current position of the file read/write pointer
Returns true if the stream is at the end of the stream.
Returns whether or not the stream is seekable.
Seek to a position in the stream.
Seek to the beginning of the stream.
Returns whether or not the stream is writable.
Write data to the stream.
Returns whether or not the stream is readable.
Read data from the stream.
Returns the remaining contents in a string
Get stream metadata as an associative array or retrieve a specific key.
Throw an exception if the current resource is not readable.
Throw an exception if the current resource is not valid.
No description
Reads all data from the stream into a string, from the beginning to end.
Details
__construct(string|resource $stream, string $mode = 'r')
No description
static ContentStream
fromContents(string $contents)
Creates an instance representing the given $contents string
void
close()
Closes the stream and any underlying resources.
resource|null
detach()
Separates any underlying resources from the stream.
After the stream has been detached, the stream is in an unusable state.
replace(string|resource $stream, string $mode = 'r')
Attach a new stream/resource to the instance.
int|null
getSize()
Get the size of the stream if known.
int
tell()
Returns the current position of the file read/write pointer
bool
eof()
Returns true if the stream is at the end of the stream.
bool
isSeekable()
Returns whether or not the stream is seekable.
bool
seek(int $offset, int $whence = SEEK_SET)
Seek to a position in the stream.
rewind()
Seek to the beginning of the stream.
If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
bool
isWritable()
Returns whether or not the stream is writable.
int
write(string $string)
Write data to the stream.
bool
isReadable()
Returns whether or not the stream is readable.
string
read(int $length)
Read data from the stream.
string
getContents()
Returns the remaining contents in a string
array|mixed|null
getMetadata(string $key = null)
Get stream metadata as an associative array or retrieve a specific key.
The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function.
protected
ensureResourceReadable()
Throw an exception if the current resource is not readable.
protected
ensureResourceOpen()
Throw an exception if the current resource is not valid.
protected bool
isValidResource($resource)
No description
string
__toString()
Reads all data from the stream into a string, from the beginning to end.
This method MUST attempt to seek to the beginning of the stream before reading data and read the stream until the end is reached.
Warning: This could attempt to load a large amount of data into memory.
This method MUST NOT raise an exception in order to conform with PHP's string casting operations.