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

Service that manages property data type definition. More...

Public Member Functions

 __construct (array $dataTypeDefinitions, array $disabledDataTypes=[])
 
 registerDataTypes (array $dataTypeDefinitions)
 Adds data type definitions.
 
 getTypeIds ()
 
 getExpertModules ()
 
 getValueTypes ()
 
 getRdfTypeUris ()
 
 getValidatorFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getParserFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getDeserializerBuilders ( $mode=self::RESOLVED_MODE)
 
 getDataValueDeserializerBuilders ()
 
 getFormatterFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getSnakFormatterFactoryCallbacks ()
 
 getRdfBuilderFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getSearchIndexDataFormatterCallbacks ( $mode=self::RESOLVED_MODE)
 Get data formatters for search indexing for each type.
 
 getRdfDataTypes ()
 Produce array of types for RDF.
 
 getNormalizerFactoryCallbacks ()
 Get data value normalizers for each type.
 

Public Attributes

const PREFIXED_MODE = 'prefixed'
 Constant for indicating that callback maps should be returned with the "VT:" and "PT:" prefixes in the array keys indicating whether the callback applies to a value type or a property data type.
 
const RESOLVED_MODE = 'resolved'
 Constant for indicating that callback maps should be returned for property data types only, with no prefixes in the array keys, but with fallbacks for value types merged into the definitions for the property data types.
 

Private Member Functions

 filterDisabledDataTypes (array $dataTypeDefinitions, array $disabledTypes)
 
 getFilteredByPrefix (array $map, $prefix)
 
 getMapForDefinitionField ( $field)
 
 resolveValueTypeFallback (array $definitions, bool $allowMissing=false)
 Resolves value type fallbacks on the given definition map.
 
 applyMode (array $callbackMap, string $mode, bool $allowMissing=false)
 Applies the given mode to the $callbackMap.
 

Private Attributes

const VALUE_TYPE_PREFIX = 'VT:'
 
const DATA_TYPE_PREFIX = 'PT:'
 
 $dataTypeDefinitions = []
 

Detailed Description

Service that manages property data type definition.

This is a registry that provides access to factory functions for various services associated with property data types, such as validators, parsers, and formatters.

DataTypeDefinitions provides a one-stop interface for defining property data types. Each property data type is defined using a "data type definition" array. A definition array has the following fields:

  • value-type: the value type used with the data type
  • validator-factory-callback: a callback for creating validators for the data type, as used by BuilderBasedDataTypeValidatorFactory.
  • parser-factory-callback: a callback for instantiating a parser for the data type
  • deserializer-builder: a callback or DataValue class string for deserializing the value
  • formatter-factory-callback: a callback for instantiating a formatter for the data type
  • rdf-builder-factory-callback: a callback for instantiating a rdf mapping for the data type

DataTypeDefinitions also supports fallback logic based on the value type associated with each property data type.

See also
docs/datatypes.wiki
Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\DataTypeDefinitions::__construct ( array $dataTypeDefinitions,
array $disabledDataTypes = [] )
Parameters
array[]$dataTypeDefinitionsAn associative array mapping property data type ids (with the prefix "PT:") and value types (with the prefix "VT:") to data type definitions. Each data type definitions are associative arrays, refer to the class level documentation for details.
string[]$disabledDataTypesArray of disabled data types.

Member Function Documentation

◆ applyMode()

Wikibase\Lib\DataTypeDefinitions::applyMode ( array $callbackMap,
string $mode,
bool $allowMissing = false )
private

Applies the given mode to the $callbackMap.

If $mode is PREFIXED_MODE, $callbackMap is returned unchanged. If $mode is RESOLVED_MODE, resolveValueTypeFallback() is applied to $callbackMap. The resulting map will have no prefixes in the array keys, and will contain entries for all property data types, with value type fallback applied.

Parameters
array$callbackMap
string$modePREFIXED_MODE or RESOLVED_MODE
bool$allowMissingSee self::resolveValueTypeFallback()
Returns
array A version of $callbackMap with $mode applied.

◆ filterDisabledDataTypes()

Wikibase\Lib\DataTypeDefinitions::filterDisabledDataTypes ( array $dataTypeDefinitions,
array $disabledTypes )
private
Parameters
array[]$dataTypeDefinitionsAssociative array of data types and definitions.
string[]$disabledTypesList of disabled data types
Returns
array[] Filtered data type definitions

◆ getDataValueDeserializerBuilders()

Wikibase\Lib\DataTypeDefinitions::getDataValueDeserializerBuilders ( )
Returns
array<callable|string> map of value type IDs to deserializer builder callbacks or DataValue class names

◆ getDeserializerBuilders()

Wikibase\Lib\DataTypeDefinitions::getDeserializerBuilders ( $mode = self::RESOLVED_MODE)
See also
SnakValueDeserializer
Parameters
string$modePREFIXED_MODE to request a callback map with "VT:" and "PT:" prefixes for value types and property data types, or RESOLVED_MODE to retrieve a builder map for property data types only, with value type fallback applied.
Returns
array<callable|string>

◆ getExpertModules()

Wikibase\Lib\DataTypeDefinitions::getExpertModules ( )

◆ getFilteredByPrefix()

Wikibase\Lib\DataTypeDefinitions::getFilteredByPrefix ( array $map,
$prefix )
private
Parameters
array$map
string$prefix
Returns
array A filtered version of $map that only contains the entries with keys that match the prefix $prefix, with that prefix removed.

◆ getFormatterFactoryCallbacks()

Wikibase\Lib\DataTypeDefinitions::getFormatterFactoryCallbacks ( $mode = self::RESOLVED_MODE)
See also
OutputFormatValueFormatterFactory
Parameters
string$modePREFIXED_MODE to request a callback map with "VT:" and "PT:" prefixes for value types and property data types, or RESOLVED_MODE to retrieve a callback map for property data types only, with value type fallback applied.
Returns
callable[]

◆ getMapForDefinitionField()

Wikibase\Lib\DataTypeDefinitions::getMapForDefinitionField ( $field)
private
Parameters
string$field
Returns
array An associative array mapping type IDs (with "VT:" or "PT:" prefixes) to the value of $field given in the original property data type definition provided to the constructor.

◆ getNormalizerFactoryCallbacks()

Wikibase\Lib\DataTypeDefinitions::getNormalizerFactoryCallbacks ( )

Get data value normalizers for each type.

Returns
callable[] List of callbacks, with keys having "VT:" and "PT:" prefixes.

◆ getParserFactoryCallbacks()

Wikibase\Lib\DataTypeDefinitions::getParserFactoryCallbacks ( $mode = self::RESOLVED_MODE)
See also
ValueParserFactory
Parameters
string$modePREFIXED_MODE to request a callback map with "VT:" and "PT:" prefixes for value types and property data types, or RESOLVED_MODE to retrieve a callback map for property data types only, with value type fallback applied.
Returns
callable[]

◆ getRdfBuilderFactoryCallbacks()

Wikibase\Lib\DataTypeDefinitions::getRdfBuilderFactoryCallbacks ( $mode = self::RESOLVED_MODE)
See also
ValueSnakRdfBuilderFactory
Parameters
string$modePREFIXED_MODE to request a callback map with "VT:" and "PT:" prefixes for value types and property data types, or RESOLVED_MODE to retrieve a callback map for property data types only, with value type fallback applied.
Returns
callable[]

◆ getRdfDataTypes()

Wikibase\Lib\DataTypeDefinitions::getRdfDataTypes ( )

Produce array of types for RDF.

Using PropertyRdfBuilder constants for data types is recommended. In situations where PropertyRdfBuilder has not been autoloaded yet, the type may be wrapped in a callback.

Returns
string[]

◆ getRdfTypeUris()

Wikibase\Lib\DataTypeDefinitions::getRdfTypeUris ( )
Returns
string[] An associative array mapping some property data types to types URIs for use in RDF. This does not have to cover all known property data types. For those that od not explicitly define a URI, RdfVocabulary will generate one. Note that property data type URIs are not intended to be used as RDF literal types.

◆ getSearchIndexDataFormatterCallbacks()

Wikibase\Lib\DataTypeDefinitions::getSearchIndexDataFormatterCallbacks ( $mode = self::RESOLVED_MODE)

Get data formatters for search indexing for each type.

Parameters
string$modePREFIXED_MODE to request a callback map with "VT:" and "PT:" prefixes for value types and property data types, or RESOLVED_MODE to retrieve a callback map for property data types only, with value type fallback applied.
Returns
callable[] A partial map with keys depending on the $mode. Note that, unlike in other methods of this class, the returned map is not guaranteed to cover all data or value types: there are several data types and value types with no defined search index data formatter.

◆ getSnakFormatterFactoryCallbacks()

Wikibase\Lib\DataTypeDefinitions::getSnakFormatterFactoryCallbacks ( )
See also
OutputFormatSnakFormatterFactory
Returns
callable[]

◆ getTypeIds()

Wikibase\Lib\DataTypeDefinitions::getTypeIds ( )
Returns
string[] a list of all registered property data types.

◆ getValidatorFactoryCallbacks()

Wikibase\Lib\DataTypeDefinitions::getValidatorFactoryCallbacks ( $mode = self::RESOLVED_MODE)
See also
BuilderBasedDataTypeValidatorFactory
Parameters
string$modePREFIXED_MODE to request a callback map with "VT:" and "PT:" prefixes for value types and property data types, or RESOLVED_MODE to retrieve a callback map for property data types only, with value type fallback applied.
Returns
callable[]

◆ getValueTypes()

Wikibase\Lib\DataTypeDefinitions::getValueTypes ( )
Returns
string[] An associative array mapping property data types to value types.

◆ registerDataTypes()

Wikibase\Lib\DataTypeDefinitions::registerDataTypes ( array $dataTypeDefinitions)

Adds data type definitions.

The new definitions are merged with the existing definitions. If a data type in $dataTypeDefinitions was already defined, the old definition is not replaced but the definitions are merged.

Parameters
array[]$dataTypeDefinitionsAn associative array mapping property data type ids (with the prefix "PT:") and value types (with the prefix "VT:") to data type definitions. Each data type definitions are associative arrays, refer to the class level documentation for details.

◆ resolveValueTypeFallback()

Wikibase\Lib\DataTypeDefinitions::resolveValueTypeFallback ( array $definitions,
bool $allowMissing = false )
private

Resolves value type fallbacks on the given definition map.

For each property data type, the corresponding value type is determined. Then, any data type missing from $definitions is filled in with the value for the corresponding value type. The resulting array will have no PT or VT prefixes.

Parameters
array$definitionsThe map to process.
bool$allowMissingWhether to allow missing definitions, i.e. known data types with no definition entry matching their data type or value type. By default, this throws an exception, so that if the function returns successfully, the resulting array is guaranteed to contain all data types.
Exceptions
UnexpectedValueException
Returns
array An associative array mapping data type IDs to one of the $definitions values. The keys in this array are plain property data type IDs without a prefix.

Member Data Documentation

◆ $dataTypeDefinitions

Wikibase\Lib\DataTypeDefinitions::$dataTypeDefinitions = []
private

◆ DATA_TYPE_PREFIX

const Wikibase\Lib\DataTypeDefinitions::DATA_TYPE_PREFIX = 'PT:'
private

◆ PREFIXED_MODE

const Wikibase\Lib\DataTypeDefinitions::PREFIXED_MODE = 'prefixed'

Constant for indicating that callback maps should be returned with the "VT:" and "PT:" prefixes in the array keys indicating whether the callback applies to a value type or a property data type.

◆ RESOLVED_MODE

const Wikibase\Lib\DataTypeDefinitions::RESOLVED_MODE = 'resolved'

Constant for indicating that callback maps should be returned for property data types only, with no prefixes in the array keys, but with fallbacks for value types merged into the definitions for the property data types.

◆ VALUE_TYPE_PREFIX

const Wikibase\Lib\DataTypeDefinitions::VALUE_TYPE_PREFIX = 'VT:'
private

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