MediaWiki REL1_37
|
Public Member Functions | |
detectNonSerializableData ( $value, bool $expectUnserialize=false) | |
Checks if the $value is JSON-serializable (contains only scalar values) and returns a JSON-path to the first non-serializable property encountered. | |
serialize ( $value) | |
Encode $value as JSON with an intent to use JsonUnserializer::unserialize to decode it back. | |
unserialize ( $json, string $expectedClass=null) | |
Restore an instance of simple type or JsonUnserializable subclass from the JSON serialization. | |
unserializeArray (array $array) | |
Helper to unserialize an array of JsonUnserializable instances or simple types. | |
Private Member Functions | |
canMakeNewFromValue ( $json) | |
Is it likely possible to make a new instance from $json serialization? | |
detectNonSerializableDataInternal ( $value, bool $expectUnserialize, string $accumulatedPath) | |
Recursive check for ability to serialize $value to JSON via FormatJson::encode(). | |
Definition at line 36 of file JsonCodec.php.
|
private |
Is it likely possible to make a new instance from $json serialization?
mixed | $json |
Definition at line 122 of file JsonCodec.php.
Referenced by MediaWiki\Json\JsonCodec\unserialize(), and MediaWiki\Json\JsonCodec\unserializeArray().
MediaWiki\Json\JsonCodec::detectNonSerializableData | ( | $value, | |
bool | $expectUnserialize = false |
||
) |
Checks if the $value is JSON-serializable (contains only scalar values) and returns a JSON-path to the first non-serializable property encountered.
mixed | $value | |
bool | $expectUnserialize | whether to expect the $value to be unserializable with JsonUnserializer. |
Definition at line 181 of file JsonCodec.php.
|
private |
Recursive check for ability to serialize $value to JSON via FormatJson::encode().
mixed | $value | |
bool | $expectUnserialize | |
string | $accumulatedPath |
Definition at line 142 of file JsonCodec.php.
MediaWiki\Json\JsonCodec::serialize | ( | $value | ) |
Encode $value as JSON with an intent to use JsonUnserializer::unserialize to decode it back.
mixed | JsonUnserializable | $value | A value to encode. Can be any scalar, array, stdClass, JsonUnserializable or any combination of them. |
InvalidArgumentException | if the value can not be serialized. |
Implements MediaWiki\Json\JsonSerializer.
Definition at line 89 of file JsonCodec.php.
References FormatJson\ALL_OK, and FormatJson\encode().
MediaWiki\Json\JsonCodec::unserialize | ( | $json, | |
string | $expectedClass = null |
||
) |
Restore an instance of simple type or JsonUnserializable subclass from the JSON serialization.
It supports passing array/object to allow manual decoding of the JSON string if needed.
@phpcs:ignore MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam
array | string | object | $json | |
string | null | $expectedClass | What class to expect in unserialization. If null, no expectation. Must be a descendant of JsonUnserializable. |
InvalidArgumentException | if the passed $json can't be unserialized. |
Implements MediaWiki\Json\JsonUnserializer.
Definition at line 38 of file JsonCodec.php.
References MediaWiki\Json\JsonCodec\canMakeNewFromValue(), FormatJson\FORCE_ASSOC, FormatJson\parse(), and MediaWiki\Json\JsonConstants\TYPE_ANNOTATION.
Referenced by MediaWiki\Json\JsonCodec\unserializeArray().
MediaWiki\Json\JsonCodec::unserializeArray | ( | array | $array | ) |
Helper to unserialize an array of JsonUnserializable instances or simple types.
array | $array |
Implements MediaWiki\Json\JsonUnserializer.
Definition at line 77 of file JsonCodec.php.
References MediaWiki\Json\JsonCodec\canMakeNewFromValue(), and MediaWiki\Json\JsonCodec\unserialize().