JsonStream
class JsonStream implements StreamInterface (View source)
Provides a http stream interface for encoding JSON.
Methods
Returns the entire JSON stream as a string.
Frees the JSON encoder from memory and prevents further reading from the JSON stream.
Detaches the underlying PHP resource from the stream and returns it.
Returns the total size of the JSON stream.
Returns the current position of the cursor in the JSON stream.
Tells if there are no more bytes to read from the JSON stream.
Tells if the JSON stream is seekable or not.
Seeks the given cursor position in the JSON stream.
Seeks the beginning of the JSON stream.
Tells if the JSON stream is writable or not.
Writes the given bytes to the JSON stream.
Tells if the JSON stream is readable or not.
Returns the given number of bytes from the JSON stream.
Returns the remaining bytes from the JSON stream.
Returns the metadata related to the JSON stream.
Details
at line 29
__construct(BufferJsonEncoder|mixed $value)
JsonStream constructor.
at line 64
string
__toString()
Returns the entire JSON stream as a string.
Note that this operation performs rewind operation on the JSON encoder. Whether this works or not is dependant on the underlying value being encoded. An empty string is returned if the value cannot be encoded.
at line 77
close()
Frees the JSON encoder from memory and prevents further reading from the JSON stream.
at line 86
null
detach()
Detaches the underlying PHP resource from the stream and returns it.
at line 95
null
getSize()
Returns the total size of the JSON stream.
at line 104
int
tell()
Returns the current position of the cursor in the JSON stream.
at line 114
bool
eof()
Tells if there are no more bytes to read from the JSON stream.
at line 123
bool
isSeekable()
Tells if the JSON stream is seekable or not.
at line 143
seek(int $offset, int $whence = SEEK_SET)
Seeks the given cursor position in the JSON stream.
If the provided seek position is less than the current cursor position, a rewind operation is performed on the underlying JSON encoder. Whether this works or not depends on whether the encoded value supports rewinding.
Note that since it's not possible to determine the end of the JSON stream without encoding the entire value, it's not possible to set the cursor using SEEK_END constant and doing so will result in an exception.
at line 212
rewind()
Seeks the beginning of the JSON stream.
If the encoding has already been started, rewinding the encoder may not work, if the underlying value being encoded does not support rewinding.
at line 221
bool
isWritable()
Tells if the JSON stream is writable or not.
at line 236
int
write(string $string)
Writes the given bytes to the JSON stream.
As the JSON stream does not represent a writable stream, this method will always throw a runtime exception.
at line 245
bool
isReadable()
Tells if the JSON stream is readable or not.
at line 262
string
read(int $length)
Returns the given number of bytes from the JSON stream.
The underlying value is encoded into JSON until enough bytes have been generated to fulfill the requested number of bytes. The extraneous bytes are then buffered for the next read from the JSON stream. The stream may return fewer number of bytes if the entire value has been encoded and there are no more bytes to return.
at line 289
string
getContents()
Returns the remaining bytes from the JSON stream.
at line 315
array|mixed|null
getMetadata(string|null $key = null)
Returns the metadata related to the JSON stream.
No underlying PHP resource exists for the stream, but this method will still return relevant information regarding the stream that is similar to PHP stream meta data.