Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Lib\Store\EntityContentDataCodec Class Reference

A codec for use by EntityContent resp EntityHandler subclasses for the serialization and deserialization of EntityContent objects. More...

Public Member Functions

 __construct (EntityIdParser $entityIdParser, Serializer $entitySerializer, Deserializer $entityDeserializer, $maxBlobSize=0)
 
 getSupportedFormats ()
 Returns the supported serialization formats as a list of strings.
 
 getDefaultFormat ()
 
 encodeEntity (EntityDocument $entity, $format)
 Encodes an Entity into a blob for storage.
 
 encodeRedirect (EntityRedirect $redirect, $format)
 Encodes an EntityRedirect into a blob for storage.
 
 decodeEntity ( $blob, $format)
 Decodes a blob loaded from storage into an Entity.
 
 decodeRedirect ( $blob, $format)
 Decodes a blob loaded from storage into an EntityRedirect.
 

Private Member Functions

 sanitizeFormat ( $format)
 Returns a sanitized version of $format.
 
 encodeEntityContentData (array $data, $format)
 Encodes the given array structure as a blob using the given serialization format.
 
 decodeEntityContentData ( $blob, $format)
 Decodes the given blob into an array structure representing an EntityContent object.
 
 extractEntityId (array $data, $key)
 

Private Attributes

 $entityIdParser
 
 $entitySerializer
 
 $entityDeserializer
 
 $maxBlobSize
 

Detailed Description

A codec for use by EntityContent resp EntityHandler subclasses for the serialization and deserialization of EntityContent objects.

This class only deals with the representation of EntityContent as an array structure, not with EntityContent objects. It is needed to allow client side code to deserialize entity content data without the need to depend on EntityContent objects, which are only available on the repo.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\Store\EntityContentDataCodec::__construct ( EntityIdParser  $entityIdParser,
Serializer  $entitySerializer,
Deserializer  $entityDeserializer,
  $maxBlobSize = 0 
)
Parameters
EntityIdParser$entityIdParser
Serializer$entitySerializerA service capable of serializing EntityDocument objects.
Deserializer$entityDeserializerA service capable of deserializing EntityDocument objects.
int$maxBlobSizeThe maximum size of a blob to allow during serialization/deserialization, in bytes. Set to 0 to disable the check.

Member Function Documentation

◆ decodeEntity()

Wikibase\Lib\Store\EntityContentDataCodec::decodeEntity (   $blob,
  $format 
)

Decodes a blob loaded from storage into an Entity.

See also
EntityHandler::unserializeContent()
Parameters
string$blob
string | null$formatThe serialization format of the data blob. One of the CONTENT_FORMAT_... constants or null for the default.
Exceptions
InvalidArgumentExceptionIf the format is not supported.
MWContentSerializationException
Returns
EntityDocument|null The entity represented by $blob, or null if $blob represents a redirect.

◆ decodeEntityContentData()

Wikibase\Lib\Store\EntityContentDataCodec::decodeEntityContentData (   $blob,
  $format 
)
private

Decodes the given blob into an array structure representing an EntityContent object.

Parameters
string$blobThe data blob to deserialize
string | null$formatThe serialization format of $blob
Exceptions
InvalidArgumentExceptionIf the format is not supported.
MWContentSerializationException
Returns
array An array representation of an EntityContent object

◆ decodeRedirect()

Wikibase\Lib\Store\EntityContentDataCodec::decodeRedirect (   $blob,
  $format 
)

Decodes a blob loaded from storage into an EntityRedirect.

See also
EntityHandler::unserializeContent()
Parameters
string$blob
string | null$formatThe serialization format of the data blob. One of the CONTENT_FORMAT_... constants or null for the default.
Exceptions
InvalidArgumentExceptionIf the format is not supported.
MWContentSerializationExceptionIf the array could not be decoded.
Returns
EntityRedirect|null The EntityRedirect represented by $blob, or null if $blob does not represent a redirect.

◆ encodeEntity()

Wikibase\Lib\Store\EntityContentDataCodec::encodeEntity ( EntityDocument  $entity,
  $format 
)

Encodes an Entity into a blob for storage.

See also
EntityHandler::serializeContent()
Parameters
EntityDocument$entity
string | null$formatThe desired serialization format. One of the CONTENT_FORMAT_... constants or null for the default.
Exceptions
MWContentSerializationException
EntityContentTooBigException
Returns
string

◆ encodeEntityContentData()

Wikibase\Lib\Store\EntityContentDataCodec::encodeEntityContentData ( array  $data,
  $format 
)
private

Encodes the given array structure as a blob using the given serialization format.

Parameters
array$dataA nested data array representing (part of) an EntityContent object.
string | null$formatThe desired serialization format.
Exceptions
InvalidArgumentExceptionIf the format is not supported.
MWContentSerializationExceptionIf the array could not be encoded.
Returns
string the blob

◆ encodeRedirect()

Wikibase\Lib\Store\EntityContentDataCodec::encodeRedirect ( EntityRedirect  $redirect,
  $format 
)

Encodes an EntityRedirect into a blob for storage.

See also
EntityHandler::serializeContent()
Parameters
EntityRedirect$redirect
string | null$formatThe desired serialization format. One of the CONTENT_FORMAT_... constants or null for the default.
Exceptions
InvalidArgumentExceptionIf the format is not supported.
MWContentSerializationException
Returns
string A blob representing the given Entity.

◆ extractEntityId()

Wikibase\Lib\Store\EntityContentDataCodec::extractEntityId ( array  $data,
  $key 
)
private
Parameters
array$dataAn array representation of an EntityContent object.
string$keyThe key in $data that contains the serialized ID.
Exceptions
MWContentSerializationException
Returns
EntityId|null The ID of the entity (resp. redirect), or null if $key is not set in $data.

◆ getDefaultFormat()

Wikibase\Lib\Store\EntityContentDataCodec::getDefaultFormat ( )
Returns
string CONTENT_FORMAT_JSON

◆ getSupportedFormats()

Wikibase\Lib\Store\EntityContentDataCodec::getSupportedFormats ( )

Returns the supported serialization formats as a list of strings.

Returns
string[]

◆ sanitizeFormat()

Wikibase\Lib\Store\EntityContentDataCodec::sanitizeFormat (   $format)
private

Returns a sanitized version of $format.

Parameters
string | null$formatThe requested format. If null, getDefaultFormat() will be consulted.
Returns
string The format to actually use.

Member Data Documentation

◆ $entityDeserializer

Wikibase\Lib\Store\EntityContentDataCodec::$entityDeserializer
private

◆ $entityIdParser

Wikibase\Lib\Store\EntityContentDataCodec::$entityIdParser
private

◆ $entitySerializer

Wikibase\Lib\Store\EntityContentDataCodec::$entitySerializer
private

◆ $maxBlobSize

Wikibase\Lib\Store\EntityContentDataCodec::$maxBlobSize
private

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