trait PreservesBigIntegers

Constants

protected BIG_INTEGER_KEY

The key a big integer is transported under.

protected MAX_SAFE_INTEGER

The largest integer JavaScript represents without losing precision.

Properties

protected bool $preserveBigIntegers

Indicates if integers outside JavaScript's safe range should be preserved.

static protected array<class-string, bool> $plainJsonClasses

Whether each encountered class serializes as its public properties.

Methods

mixed
encodeBigIntegersWhenEnabled(mixed $value)

Wrap big integers only when this response opted in.

mixed
encodeBigIntegers(mixed $value, SplObjectStorage|null $seen = null)

Wrap integers outside JavaScript's safe integer range as a marker so the frontend can revive them as native BigInt values without losing precision when the JSON response is parsed.

array
encodeBigIntegersInArray(array $value, SplObjectStorage|null $seen)

Wrap the big integers held by the given array.

mixed
encodeBigIntegersInObject(object $value, SplObjectStorage $seen)

Wrap the big integers held by the given object, unwrapping it the same way json_encode would so the shape it emits is unchanged. Objects are cast back so they keep serializing as a JSON object, not an array.

bool
hasPlainJsonRepresentation(object $value)

Determine if the object's public properties are what json_encode emits.

Details

at line 43
protected mixed encodeBigIntegersWhenEnabled(mixed $value)

Wrap big integers only when this response opted in.

Parameters

mixed $value

Return Value

mixed

at line 55
protected mixed encodeBigIntegers(mixed $value, SplObjectStorage|null $seen = null)

Wrap integers outside JavaScript's safe integer range as a marker so the frontend can revive them as native BigInt values without losing precision when the JSON response is parsed.

Parameters

mixed $value
SplObjectStorage|null $seen

Return Value

mixed

at line 96
protected array encodeBigIntegersInArray(array $value, SplObjectStorage|null $seen)

Wrap the big integers held by the given array.

Parameters

array $value
SplObjectStorage|null $seen

Return Value

array

at line 116
protected mixed encodeBigIntegersInObject(object $value, SplObjectStorage $seen)

Wrap the big integers held by the given object, unwrapping it the same way json_encode would so the shape it emits is unchanged. Objects are cast back so they keep serializing as a JSON object, not an array.

Parameters

object $value
SplObjectStorage $seen

Return Value

mixed

at line 145
protected bool hasPlainJsonRepresentation(object $value)

Determine if the object's public properties are what json_encode emits.

Parameters

object $value

Return Value

bool