Wikibase
MediaWiki Wikibase extension
|
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 = [] | |
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:
DataTypeDefinitions also supports fallback logic based on the value type associated with each property data type.
Wikibase\Lib\DataTypeDefinitions::__construct | ( | array | $dataTypeDefinitions, |
array | $disabledDataTypes = [] ) |
array[] | $dataTypeDefinitions | An 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[] | $disabledDataTypes | Array of disabled data types. |
|
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.
array | $callbackMap | |
string | $mode | PREFIXED_MODE or RESOLVED_MODE |
bool | $allowMissing | See self::resolveValueTypeFallback() |
|
private |
array[] | $dataTypeDefinitions | Associative array of data types and definitions. |
string[] | $disabledTypes | List of disabled data types |
Wikibase\Lib\DataTypeDefinitions::getDataValueDeserializerBuilders | ( | ) |
Wikibase\Lib\DataTypeDefinitions::getDeserializerBuilders | ( | $mode = self::RESOLVED_MODE | ) |
string | $mode | PREFIXED_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. |
Wikibase\Lib\DataTypeDefinitions::getExpertModules | ( | ) |
|
private |
array | $map | |
string | $prefix |
Wikibase\Lib\DataTypeDefinitions::getFormatterFactoryCallbacks | ( | $mode = self::RESOLVED_MODE | ) |
string | $mode | PREFIXED_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. |
|
private |
string | $field |
Wikibase\Lib\DataTypeDefinitions::getNormalizerFactoryCallbacks | ( | ) |
Get data value normalizers
for each type.
Wikibase\Lib\DataTypeDefinitions::getParserFactoryCallbacks | ( | $mode = self::RESOLVED_MODE | ) |
string | $mode | PREFIXED_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. |
Wikibase\Lib\DataTypeDefinitions::getRdfBuilderFactoryCallbacks | ( | $mode = self::RESOLVED_MODE | ) |
string | $mode | PREFIXED_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. |
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.
Wikibase\Lib\DataTypeDefinitions::getRdfTypeUris | ( | ) |
Wikibase\Lib\DataTypeDefinitions::getSearchIndexDataFormatterCallbacks | ( | $mode = self::RESOLVED_MODE | ) |
Get data formatters for search indexing for each type.
string | $mode | PREFIXED_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. |
Wikibase\Lib\DataTypeDefinitions::getSnakFormatterFactoryCallbacks | ( | ) |
Wikibase\Lib\DataTypeDefinitions::getTypeIds | ( | ) |
Wikibase\Lib\DataTypeDefinitions::getValidatorFactoryCallbacks | ( | $mode = self::RESOLVED_MODE | ) |
string | $mode | PREFIXED_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. |
Wikibase\Lib\DataTypeDefinitions::getValueTypes | ( | ) |
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.
array[] | $dataTypeDefinitions | An 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. |
|
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.
array | $definitions | The map to process. |
bool | $allowMissing | Whether 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. |
UnexpectedValueException |
|
private |
|
private |
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.
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.
|
private |