Wikibase
MediaWiki Wikibase extension
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. More...
 
 getTypeIds ()
 
 getExpertModules ()
 
 getValueTypes ()
 
 getRdfTypeUris ()
 
 getValidatorFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getParserFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getFormatterFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getSnakFormatterFactoryCallbacks ()
 
 getRdfBuilderFactoryCallbacks ( $mode=self::RESOLVED_MODE)
 
 getSearchIndexDataFormatterCallbacks ()
 Get data formatters for search indexing for each type. More...
 
 getRdfDataTypes ()
 Produce array of types for RDF. More...
 

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. More...
 

Private Member Functions

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

Private Attributes

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. More...
 
 $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
  • 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,
  $mode 
)
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
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

◆ 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.

◆ 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 ( )

Get data formatters for search indexing for each type.

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

◆ 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)
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.
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

◆ 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'
private

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.


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