Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\LinkedData\EntityDataSerializationService Class Reference

Service for serializing entity data. More...

Public Member Functions

 __construct (EntityLookup $entityLookup, EntityTitleStoreLookup $entityTitleStoreLookup, EntityContentFactory $entityContentFactory, PropertyDataTypeLookup $propertyLookup, ValueSnakRdfBuilderFactory $valueSnakRdfBuilderFactory, EntityRdfBuilderFactory $entityRdfBuilderFactory, EntityDataFormatProvider $entityDataFormatProvider, SerializerFactory $serializerFactory, Serializer $entitySerializer, SiteLookup $siteLookup, RdfVocabulary $rdfVocabulary)
 
 getSerializedData ( $format, EntityRevision $entityRevision, RedirectRevision $followedRedirect=null, array $incomingRedirects=[], $flavor=null)
 Output entity data. More...
 

Private Member Functions

 rdfSerialize (EntityRevision $entityRevision, ?RedirectRevision $followedRedirect, array $incomingRedirects, RdfBuilder $rdfBuilder, $flavor=null)
 
 addIncomingRedirects (EntityId $targetId, ?EntityRedirect $followedRedirect, array $incomingRedirects, RdfBuilder $rdfBuilder)
 
 newApiMain ( $format)
 Returns an ApiMain module that acts as a context for the formatting and serialization. More...
 
 createApiSerializer ( $formatName)
 Creates an API printer that can generate the given output format. More...
 
 getFlavor ( $flavorName)
 Get the producer setting for current data format. More...
 
 createRdfBuilder ( $format, $flavorName=null)
 Creates an Rdf Serializer that can generate the given output format. More...
 
 generateApiResult (EntityRevision $entityRevision, ApiFormatBase $printer)
 Pushes the given $entity into the ApiResult held by the ApiMain module returned by newApiMain(). More...
 
 getApiSerialization (EntityRevision $entityRevision, ApiFormatBase $printer)
 Serialize the entity data using the provided format. More...
 

Private Attributes

 $entityLookup = null
 
 $entityTitleStoreLookup
 
 $entityContentFactory
 
 $serializerFactory
 
 $entitySerializer
 
 $propertyLookup
 
 $entityDataFormatProvider
 
 $rdfWriterFactory
 
 $siteLookup
 
 $rdfVocabulary
 
 $valueSnakRdfBuilderFactory
 
 $entityRdfBuilderFactory
 

Detailed Description

Service for serializing entity data.

Note that we are using the API's serialization facility to ensure a consistent external representation of data entities. Using the ContentHandler to serialize the entity would expose internal implementation details.

For RDF output, this relies on the RdfBuilder class.

Author
Daniel Kinzler
Thomas Pellissier Tanon
Anja Jentzsch < anja..nosp@m.jent.nosp@m.zsch@.nosp@m.wiki.nosp@m.media.nosp@m..de >

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\LinkedData\EntityDataSerializationService::__construct ( EntityLookup  $entityLookup,
EntityTitleStoreLookup  $entityTitleStoreLookup,
EntityContentFactory  $entityContentFactory,
PropertyDataTypeLookup  $propertyLookup,
ValueSnakRdfBuilderFactory  $valueSnakRdfBuilderFactory,
EntityRdfBuilderFactory  $entityRdfBuilderFactory,
EntityDataFormatProvider  $entityDataFormatProvider,
SerializerFactory  $serializerFactory,
Serializer  $entitySerializer,
SiteLookup  $siteLookup,
RdfVocabulary  $rdfVocabulary 
)

Member Function Documentation

◆ addIncomingRedirects()

Wikibase\Repo\LinkedData\EntityDataSerializationService::addIncomingRedirects ( EntityId  $targetId,
?EntityRedirect  $followedRedirect,
array  $incomingRedirects,
RdfBuilder  $rdfBuilder 
)
private
Parameters
EntityId$targetId
EntityRedirect | null$followedRedirectThe followed redirect, will be omitted from the output.
EntityId[]$incomingRedirects
RdfBuilder$rdfBuilder

◆ createApiSerializer()

Wikibase\Repo\LinkedData\EntityDataSerializationService::createApiSerializer (   $formatName)
private

Creates an API printer that can generate the given output format.

Parameters
string$formatNameThe desired serialization format, as a format name understood by ApiBase or RdfWriterFactory.
Returns
ApiFormatBase|null A suitable result printer, or null if the given format is not supported by the API.

◆ createRdfBuilder()

Wikibase\Repo\LinkedData\EntityDataSerializationService::createRdfBuilder (   $format,
  $flavorName = null 
)
private

Creates an Rdf Serializer that can generate the given output format.

Parameters
string$formatThe desired serialization format, as a format name understood by ApiBase or RdfWriterFactory
string | null$flavorNameFlavor name (used for RDF output)
Returns
RdfBuilder|null A suitable result printer, or null if the given format is not supported.

◆ generateApiResult()

Wikibase\Repo\LinkedData\EntityDataSerializationService::generateApiResult ( EntityRevision  $entityRevision,
ApiFormatBase  $printer 
)
private

Pushes the given $entity into the ApiResult held by the ApiMain module returned by newApiMain().

Calling $printer->execute() later will output this result, if $printer was generated from that same ApiMain module, as createApiPrinter() does.

Parameters
EntityRevision$entityRevisionThe entity to convert ot an ApiResult
ApiFormatBase$printerThe output printer that will be used for serialization. Used to provide context for generating the ApiResult, and may also be manipulated to fine-tune the output.
Returns
ApiResult

◆ getApiSerialization()

Wikibase\Repo\LinkedData\EntityDataSerializationService::getApiSerialization ( EntityRevision  $entityRevision,
ApiFormatBase  $printer 
)
private

Serialize the entity data using the provided format.

Note that we are using the API's serialization facility to ensure a consistent external representation of data entities. Using the ContentHandler to serialize the entity would expose internal implementation details.

Parameters
EntityRevision$entityRevisionthe entity to output.
ApiFormatBase$printerthe printer to use to generate the output
Returns
string the serialized data

◆ getFlavor()

Wikibase\Repo\LinkedData\EntityDataSerializationService::getFlavor (   $flavorName)
private

Get the producer setting for current data format.

Parameters
string | null$flavorName
Returns
int
Exceptions
MWException

◆ getSerializedData()

Wikibase\Repo\LinkedData\EntityDataSerializationService::getSerializedData (   $format,
EntityRevision  $entityRevision,
RedirectRevision  $followedRedirect = null,
array  $incomingRedirects = [],
  $flavor = null 
)

Output entity data.

Parameters
string$formatThe name (mime type of file extension) of the format to use
EntityRevision$entityRevisionThe entity
RedirectRevision | null$followedRedirectThe redirect that led to the entity, or null
EntityId[]$incomingRedirectsIncoming redirects to include in the output
string | null$flavorThe type of the output provided by serializer
Returns
array tuple of ( $data, $contentType )
Exceptions
MWException

◆ newApiMain()

Wikibase\Repo\LinkedData\EntityDataSerializationService::newApiMain (   $format)
private

Returns an ApiMain module that acts as a context for the formatting and serialization.

Parameters
string$formatThe desired output format, as a format name that ApiBase understands.
Returns
ApiMain

◆ rdfSerialize()

Wikibase\Repo\LinkedData\EntityDataSerializationService::rdfSerialize ( EntityRevision  $entityRevision,
?RedirectRevision  $followedRedirect,
array  $incomingRedirects,
RdfBuilder  $rdfBuilder,
  $flavor = null 
)
private
Parameters
EntityRevision$entityRevision
RedirectRevision | null$followedRedirecta redirect leading to the entity for use in the output
EntityId[]$incomingRedirectsIncoming redirects to include in the output
RdfBuilder$rdfBuilder
string | null$flavorThe type of the output provided by serializer
Returns
string RDF

Member Data Documentation

◆ $entityContentFactory

Wikibase\Repo\LinkedData\EntityDataSerializationService::$entityContentFactory
private

◆ $entityDataFormatProvider

Wikibase\Repo\LinkedData\EntityDataSerializationService::$entityDataFormatProvider
private

◆ $entityLookup

Wikibase\Repo\LinkedData\EntityDataSerializationService::$entityLookup = null
private

◆ $entityRdfBuilderFactory

Wikibase\Repo\LinkedData\EntityDataSerializationService::$entityRdfBuilderFactory
private

◆ $entitySerializer

Wikibase\Repo\LinkedData\EntityDataSerializationService::$entitySerializer
private

◆ $entityTitleStoreLookup

Wikibase\Repo\LinkedData\EntityDataSerializationService::$entityTitleStoreLookup
private

◆ $propertyLookup

Wikibase\Repo\LinkedData\EntityDataSerializationService::$propertyLookup
private

◆ $rdfVocabulary

Wikibase\Repo\LinkedData\EntityDataSerializationService::$rdfVocabulary
private

◆ $rdfWriterFactory

Wikibase\Repo\LinkedData\EntityDataSerializationService::$rdfWriterFactory
private

◆ $serializerFactory

Wikibase\Repo\LinkedData\EntityDataSerializationService::$serializerFactory
private

◆ $siteLookup

Wikibase\Repo\LinkedData\EntityDataSerializationService::$siteLookup
private

◆ $valueSnakRdfBuilderFactory

Wikibase\Repo\LinkedData\EntityDataSerializationService::$valueSnakRdfBuilderFactory
private

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