StreamJsonEncoder
class StreamJsonEncoder extends AbstractJsonEncoder (View source)
Encodes value into JSON and directly echoes it or passes it to a stream.
Methods
StreamJsonEncoder constructor.
Returns the list of errors that occurred during the last encoding process.
Returns the bytes written in the last step or null if the encoder is not in valid state.
Returns the JSON encoding to the beginning.
Iterates the next token or tokens to the output stream.
Resolves the actual value of any given value that is about to be processed.
Echoes to given string or passes it to the stream callback.
Encodes the entire value into JSON and returns the number bytes.
Details
at line 33
__construct(mixed $value, callable $stream = null)
StreamJsonEncoder constructor.
If a callable is given as the second argument, the callable will be called with two arguments. The first argument is the JSON string to output and the second argument is the type of the token being outputted.
If no second parameter is passed to the constructor, then the encoder will simply output the json using an echo statement.
in AbstractJsonEncoder at line 68
$this
setOptions(int $options)
Sets the JSON encoding options.
in AbstractJsonEncoder at line 84
$this
setIndent(string|int $indent)
Sets the indent for the JSON output.
in AbstractJsonEncoder at line 98
string[]
getErrors()
Returns the list of errors that occurred during the last encoding process.
in AbstractJsonEncoder at line 107
protected array
getValueStack()
Returns the current encoding value stack.
in AbstractJsonEncoder at line 126
int|null
key()
Returns the current number of step in the encoder.
in AbstractJsonEncoder at line 137
bool
valid()
Tells if the encoder has a valid current state.
at line 75
mixed
current()
Returns the bytes written in the last step or null if the encoder is not in valid state.
at line 56
rewind()
Returns the JSON encoding to the beginning.
at line 64
next()
Iterates the next token or tokens to the output stream.
in AbstractJsonEncoder at line 261
protected mixed
resolveValue(mixed $value)
Resolves the actual value of any given value that is about to be processed.
at line 85
protected void
write(string $string, int $token)
Echoes to given string or passes it to the stream callback.
at line 44
int
encode()
Encodes the entire value into JSON and returns the number bytes.