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

DispatchingValueFormatter is a formatter for DataValues. More...

+ Inheritance diagram for Wikibase\Lib\Formatters\DispatchingValueFormatter:
+ Collaboration diagram for Wikibase\Lib\Formatters\DispatchingValueFormatter:

Public Member Functions

 __construct (array $formatters)
 
 formatValue (DataValue $value, $dataTypeId=null)
 
 format ( $value)
 

Private Attributes

 $formatters
 

Detailed Description

DispatchingValueFormatter is a formatter for DataValues.

In addition to dispatching based on the DataValue type, it also supports dispatching based on a DataType.

Todo
Plain format() shouldn't be supported, formatValue() should require the dataType ID.
Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\Formatters\DispatchingValueFormatter::__construct ( array $formatters)
Parameters
ValueFormatter[]$formattersMaps prefixed type ids to ValueFormatter instances. Each type ID must be prefixed with either "PT:" for property data types or "VT:" for data value types.
Exceptions
InvalidArgumentException

Member Function Documentation

◆ format()

Wikibase\Lib\Formatters\DispatchingValueFormatter::format ( $value)
See also
ValueFormatter::format
Deprecated
Use formatValue() instead
Parameters
DataValue$valueThe value to format
Exceptions
IllegalValueException
Returns
string

◆ formatValue()

Wikibase\Lib\Formatters\DispatchingValueFormatter::formatValue ( DataValue $value,
$dataTypeId = null )
See also
ValueFormatter::format

Formats the given value by finding an appropriate formatter among the ones supplied to the constructor, and applying it.

If $dataTypeId is given, this will first try to find an appropriate formatter based on the data type. If none is found, this falls back to finding a formatter based on the value's type.

See also
TypedValueFormatter::formatValue
Parameters
DataValue$value
string | null$dataTypeId
Exceptions
FormattingException
Returns
string

Implements Wikibase\Lib\Formatters\TypedValueFormatter.

Member Data Documentation

◆ $formatters

Wikibase\Lib\Formatters\DispatchingValueFormatter::$formatters
private

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