class BufferJsonEncoder extends AbstractJsonEncoder (View source)

Encodes the given value as JSON and returns encoding result step by step.

Methods

__construct(mixed $value)

AbstractJsonEncoder constructor.

$this
setOptions(int $options)

Sets the JSON encoding options.

$this
setIndent(string|int $indent)

Sets the indent for the JSON output.

string[]
getErrors()

Returns the list of errors that occurred during the last encoding process.

array
getValueStack()

Returns the current encoding value stack.

int|null
key()

Returns the current number of step in the encoder.

bool
valid()

Tells if the encoder has a valid current state.

mixed
current()

Returns the JSON encoded in the current step.

rewind()

Returns the JSON encoding to the beginning.

next()

Iterates the next token or tokens to the output stream.

mixed
resolveValue(mixed $value)

Resolves the actual value of any given value that is about to be processed.

void
write(string $string, int $token)

Writes the JSON output to the step buffer.

string
encode()

Encodes the entire value as JSON and returns the value as a string.

Details

__construct(mixed $value)

AbstractJsonEncoder constructor.

Parameters

mixed $value The value to encode as JSON

$this setOptions(int $options)

Sets the JSON encoding options.

Parameters

int $options The JSON encoding options that are used by json_encode

Return Value

$this Returns self for call chaining

Exceptions

RuntimeException If changing encoding options during encoding operation

$this setIndent(string|int $indent)

Sets the indent for the JSON output.

Parameters

string|int $indent A string to use as indent or the number of spaces

Return Value

$this Returns self for call chaining

Exceptions

RuntimeException If changing indent during encoding operation

string[] getErrors()

Returns the list of errors that occurred during the last encoding process.

Return Value

string[] List of errors that occurred during encoding

protected array getValueStack()

Returns the current encoding value stack.

Return Value

array The current encoding value stack

int|null key()

Returns the current number of step in the encoder.

Return Value

int|null The current step number as integer or null if the current state is not valid

bool valid()

Tells if the encoder has a valid current state.

Return Value

bool True if the iterator has a valid state, false if not

mixed current()

Returns the JSON encoded in the current step.

Return Value

mixed The current value or state from the encoder

rewind()

Returns the JSON encoding to the beginning.

next()

Iterates the next token or tokens to the output stream.

protected mixed resolveValue(mixed $value)

Resolves the actual value of any given value that is about to be processed.

Parameters

mixed $value The value to resolve

Return Value

mixed The resolved value

protected void write(string $string, int $token)

Writes the JSON output to the step buffer.

Parameters

string $string The given token to write
int $token The type of the token

Return Value

void

string encode()

Encodes the entire value as JSON and returns the value as a string.

Return Value

string The encoded JSON