Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Repo\LinkedData\EntityDataSerializationService Class Reference

Service for serializing entity data. More...

Public Member Functions

 __construct (EntityTitleStoreLookup $entityTitleStoreLookup, PropertyDataTypeLookup $propertyLookup, EntityDataFormatProvider $entityDataFormatProvider, SerializerFactory $serializerFactory, Serializer $entitySerializer, SiteLookup $siteLookup, RdfBuilderFactory $rdfBuilderFactory, EntityIdParser $entityIdParser)
 
 getSerializedData (string $format, EntityRevision $entityRevision, RedirectRevision $followedRedirect=null, array $incomingRedirects=[], ?string $flavor=null)
 Output entity data.
 

Private Member Functions

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

Private Attributes

 $entityTitleStoreLookup
 
 $serializerFactory
 
 $entitySerializer
 
 $propertyLookup
 
 $entityDataFormatProvider
 
 $rdfWriterFactory
 
 $siteLookup
 
 $rdfBuilderFactory
 
 $entityIdParser
 

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 ( EntityTitleStoreLookup $entityTitleStoreLookup,
PropertyDataTypeLookup $propertyLookup,
EntityDataFormatProvider $entityDataFormatProvider,
SerializerFactory $serializerFactory,
Serializer $entitySerializer,
SiteLookup $siteLookup,
RdfBuilderFactory $rdfBuilderFactory,
EntityIdParser $entityIdParser )

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 ( string $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 ( string $format,
?string $flavorName )
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)
Exceptions
UnknownFlavorException
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.

◆ 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 ( ?string $flavorName)
private

Get the producer setting for current data format.

Exceptions
UnknownFlavorException

◆ getSerializedData()

Wikibase\Repo\LinkedData\EntityDataSerializationService::getSerializedData ( string $format,
EntityRevision $entityRevision,
RedirectRevision $followedRedirect = null,
array $incomingRedirects = [],
?string $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
UnknownFlavorException

◆ newApiMain()

Wikibase\Repo\LinkedData\EntityDataSerializationService::newApiMain ( string $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.

◆ rdfSerialize()

Wikibase\Repo\LinkedData\EntityDataSerializationService::rdfSerialize ( EntityRevision $entityRevision,
?RedirectRevision $followedRedirect,
array $incomingRedirects,
RdfBuilder $rdfBuilder,
?string $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

◆ $entityDataFormatProvider

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

◆ $entityIdParser

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

◆ $entitySerializer

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

◆ $entityTitleStoreLookup

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

◆ $propertyLookup

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

◆ $rdfBuilderFactory

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

◆ $rdfWriterFactory

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

◆ $serializerFactory

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

◆ $siteLookup

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

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