class AbstractJsonEncoder implements Iterator (View source)

Abstract encoder for encoding JSON iteratively.

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 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.

mixed
resolveValue(mixed $value)

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

void
write(string $string, int $token)

Actually handles the writing of the given token to the output stream.

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

abstract mixed current()

Returns the current value or state from the encoder.

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

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

Actually handles the writing of the given token to the output stream.

Parameters

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

Return Value

void