DispatchingValueFormatter is a formatter for DataValues.
More...
|
| getFormatter ( $dataValueType, $dataTypeId=null) |
| Finds an appropriate formatter among the ones supplied to the constructor.
|
|
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.
- Copyright
- GPL-2.0-or-later
- Author
- Daniel Kinzler
◆ __construct()
Wikibase\Lib\Formatters\DispatchingValueFormatter::__construct |
( |
array | $formatters | ) |
|
- Parameters
-
(ValueFormatter|callable)[] | $formatters Maps prefixed type ids to ValueFormatter instances or factories. Each type ID must be prefixed with either "PT:" for property data types or "VT:" for data value types. Callables will be called on-demand with no arguments and must returne a ValueFormatter instance. |
- Exceptions
-
◆ format()
Wikibase\Lib\Formatters\DispatchingValueFormatter::format |
( |
| $value | ) |
|
- See also
- ValueFormatter::format
- Deprecated
- Use formatValue() instead
- Parameters
-
DataValue | $value | The value to format |
- Exceptions
-
- 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
-
- Returns
- string
Implements Wikibase\Lib\Formatters\TypedValueFormatter.
◆ getFormatter()
Wikibase\Lib\Formatters\DispatchingValueFormatter::getFormatter |
( |
| $dataValueType, |
|
|
| $dataTypeId = null ) |
|
protected |
Finds an appropriate formatter among the ones supplied to the constructor.
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 $dataValueType.
- Parameters
-
string | $dataValueType | |
string | null | $dataTypeId | |
- Returns
- ValueFormatter
- Exceptions
-
FormattingException | if no appropriate formatter is found |
◆ $formatters
Wikibase\Lib\Formatters\DispatchingValueFormatter::$formatters |
|
private |
The documentation for this class was generated from the following file: