MediaWiki master
MediaWiki\Json\JsonCodec Class Reference

Inherits Wikimedia\JsonCodec\JsonCodec, and MediaWiki\Json\JsonDeserializer.

Collaboration diagram for MediaWiki\Json\JsonCodec:

Public Member Functions

 __construct (?ContainerInterface $services=null)
 Create a new JsonCodec, with optional access to the provided services.
 
 deserialize ( $json, ?string $expectedClass=null)
 Restore an instance of simple type or JsonDeserializable subclass from the JSON serialization.It supports passing array/object to allow manual decoding of the JSON string if needed.
Note
JSON objects are unconditionally deserialized as PHP associative arrays, and not as instances of \stdClass.
Parameters
array | string | object$json
string | null$expectedClassWhat class to expect in deserialization. If null, no expectation. Must be a descendant of JsonDeserializable.
Exceptions
JsonExceptionif the passed $json can't be deserialized.
Returns
mixed

 
 deserializeArray (array $array)
 Helper to deserialize an array of JsonDeserializable instances or simple types.
 
 detectNonSerializableData ( $value, bool $expectDeserialize=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)
 
 unserialize ( $json, ?string $expectedClass=null)
 
 unserializeArray (array $array)
 

Protected Member Functions

 codecFor (string $className)
 Support the JsonCodecable interface by maintaining a mapping of class names to codecs.
 
 isArrayMarked (array $value)
 
 markArray (array &$value, string $className, ?string $classHint)
 
 unmarkArray (array &$value, ?string $classHint)
 

Detailed Description

Definition at line 28 of file JsonCodec.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Json\JsonCodec::__construct ( ?ContainerInterface $services = null)

Create a new JsonCodec, with optional access to the provided services.

Definition at line 49 of file JsonCodec.php.

Member Function Documentation

◆ codecFor()

MediaWiki\Json\JsonCodec::codecFor ( string $className)
protected

Support the JsonCodecable interface by maintaining a mapping of class names to codecs.

Parameters
class-string$className
Returns
?JsonClassCodec

Definition at line 59 of file JsonCodec.php.

◆ deserialize()

MediaWiki\Json\JsonCodec::deserialize ( $json,
?string $expectedClass = null )

Restore an instance of simple type or JsonDeserializable subclass from the JSON serialization.It supports passing array/object to allow manual decoding of the JSON string if needed.

Note
JSON objects are unconditionally deserialized as PHP associative arrays, and not as instances of \stdClass.
Parameters
array | string | object$json
string | null$expectedClassWhat class to expect in deserialization. If null, no expectation. Must be a descendant of JsonDeserializable.
Exceptions
JsonExceptionif the passed $json can't be deserialized.
Returns
mixed

Implements MediaWiki\Json\JsonDeserializer.

Definition at line 137 of file JsonCodec.php.

Referenced by BenchmarkJsonCodec\execute().

◆ deserializeArray()

MediaWiki\Json\JsonCodec::deserializeArray ( array $array)

Helper to deserialize an array of JsonDeserializable instances or simple types.

Parameters
array$array
Returns
array

Implements MediaWiki\Json\JsonDeserializer.

Definition at line 189 of file JsonCodec.php.

◆ detectNonSerializableData()

MediaWiki\Json\JsonCodec::detectNonSerializableData ( $value,
bool $expectDeserialize = false )

Checks if the $value is JSON-serializable (contains only scalar values) and returns a JSON-path to the first non-serializable property encountered.

Parameters
mixed$value
bool$expectDeserializewhether to expect the $value to be deserializable with JsonDeserializer.
Returns
string|null JSON path to the first encountered non-serializable property or null.
See also
JsonDeserializer
Since
1.36

Definition at line 321 of file JsonCodec.php.

Referenced by BenchmarkJsonCodec\execute().

◆ isArrayMarked()

MediaWiki\Json\JsonCodec::isArrayMarked ( array $value)
protected

Definition at line 99 of file JsonCodec.php.

◆ markArray()

MediaWiki\Json\JsonCodec::markArray ( array & $value,
string $className,
?string $classHint )
protected

◆ serialize()

MediaWiki\Json\JsonCodec::serialize ( $value)

Definition at line 200 of file JsonCodec.php.

Referenced by BenchmarkJsonCodec\execute().

◆ unmarkArray()

MediaWiki\Json\JsonCodec::unmarkArray ( array & $value,
?string $classHint )
protected

Definition at line 112 of file JsonCodec.php.

◆ unserialize()

MediaWiki\Json\JsonCodec::unserialize ( $json,
?string $expectedClass = null )
Deprecated
since 1.43; use ::deserialize()

Implements MediaWiki\Json\JsonDeserializer.

Definition at line 131 of file JsonCodec.php.

References wfDeprecated().

◆ unserializeArray()

MediaWiki\Json\JsonCodec::unserializeArray ( array $array)
Deprecated
since 1.43; use ::deserializeArray()

Implements MediaWiki\Json\JsonDeserializer.

Definition at line 184 of file JsonCodec.php.


The documentation for this class was generated from the following file: