PreservesBigIntegers
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
Wrap big integers only when this response opted in.
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.
Wrap the big integers held by the given array.
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.
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.
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.
at line 96
protected array
encodeBigIntegersInArray(array $value, SplObjectStorage|null $seen)
Wrap the big integers held by the given 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.
at line 145
protected bool
hasPlainJsonRepresentation(object $value)
Determine if the object's public properties are what json_encode emits.