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

DispatchingSnakFormatter will format a Snak by delegating the formatting to an appropriate SnakFormatter based on the snak type or the associated property's data type. More...

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

Public Member Functions

 __construct (string $format, PropertyDataTypeLookup $dataTypeLookup, array $formattersBySnakType, array $formattersByDataType)
 
 formatSnak (Snak $snak)
 
 getFormat ()
 

Private Member Functions

 assertFormatterArray ( $format, array $formatters)
 
 getBaseFormat ( $format)
 
 getSnakDataType (Snak $snak)
 

Private Attributes

 $format
 
 $dataTypeLookup
 
 $formattersByDataType
 
 $formattersBySnakType
 

Additional Inherited Members

- Public Attributes inherited from Wikibase\Lib\Formatters\SnakFormatter
const OPT_LANG = ValueFormatter::OPT_LANG
 Options key for controlling the output language.
 
const FORMAT_PLAIN = 'text/plain'
 Output format types.
 
const FORMAT_WIKI = 'text/x-wiki'
 
const FORMAT_HTML = 'text/html'
 
const FORMAT_HTML_DIFF = 'text/html; disposition=diff'
 
const FORMAT_HTML_VERBOSE = 'text/html; disposition=verbose'
 
const FORMAT_HTML_VERBOSE_PREVIEW = 'text/html; disposition=verbose-preview'
 
const OPT_ON_ERROR = 'on-error'
 Options key for controlling error handling.
 
const ON_ERROR_WARN = 'warn'
 Value for the OPT_ON_ERROR option indicating that recoverable errors should cause a warning to be show to the user.
 
const ON_ERROR_FAIL = 'fail'
 Value for the OPT_ON_ERROR option indicating that recoverable errors should cause the formatting to fail with an exception.
 

Detailed Description

DispatchingSnakFormatter will format a Snak by delegating the formatting to an appropriate SnakFormatter based on the snak type or the associated property's data type.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\Formatters\DispatchingSnakFormatter::__construct ( string $format,
PropertyDataTypeLookup $dataTypeLookup,
array $formattersBySnakType,
array $formattersByDataType )
Parameters
string$formatThe output format generated by this formatter. All SnakFormatters provided via $formattersBySnakType and $formattersByDataType must be safe for this output format. This is checked by comparing the $format with what each SnakFormatter returns from getFormat(). MIME parameters are ignored for this check, so FORMAT_HTML is considered compatible with FORMAT_HTML_DIFF, etc.
PropertyDataTypeLookup$dataTypeLookup
SnakFormatter[]$formattersBySnakTypeAn associative array mapping snak types to SnakFormatter objects. If no formatter is defined for the a given snak type, $formattersByDataType will be checked for a SnakFormatter for the snak's data type.
SnakFormatter[]$formattersByDataTypeAn associative array mapping data types to SnakFormatter objects. If no formatter is defined for the a given data type, the "*" key in this array is checked for a default formatter.
Exceptions
InvalidArgumentExceptionIf any of the given formatters is incompatible with $format. Formats are assumed to be represented by MIME types, MIME parameters are ignored.

Member Function Documentation

◆ assertFormatterArray()

Wikibase\Lib\Formatters\DispatchingSnakFormatter::assertFormatterArray ( $format,
array $formatters )
private
Parameters
string$formatMIME type
SnakFormatter[]$formatters
Exceptions
InvalidArgumentException

◆ formatSnak()

Wikibase\Lib\Formatters\DispatchingSnakFormatter::formatSnak ( Snak $snak)
See also
SnakFormatter::formatSnak

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

Parameters
Snak$snak
Exceptions
FormattingException
PropertyDataTypeLookupException
Returns
string The formatted snak value, in the format specified by getFormat().

Implements Wikibase\Lib\Formatters\SnakFormatter.

◆ getBaseFormat()

Wikibase\Lib\Formatters\DispatchingSnakFormatter::getBaseFormat ( $format)
private
Parameters
string$formatMIME type
Returns
string MIME type with parameters stripped.

◆ getFormat()

Wikibase\Lib\Formatters\DispatchingSnakFormatter::getFormat ( )
See also
SnakFormatter::getFormat
Returns
string One of the SnakFormatter::FORMAT_... constants.

Implements Wikibase\Lib\Formatters\SnakFormatter.

◆ getSnakDataType()

Wikibase\Lib\Formatters\DispatchingSnakFormatter::getSnakDataType ( Snak $snak)
private
Parameters
Snak$snak
Exceptions
PropertyDataTypeLookupException
Returns
string The Snak's data type

Member Data Documentation

◆ $dataTypeLookup

Wikibase\Lib\Formatters\DispatchingSnakFormatter::$dataTypeLookup
private

◆ $format

Wikibase\Lib\Formatters\DispatchingSnakFormatter::$format
private

◆ $formattersByDataType

Wikibase\Lib\Formatters\DispatchingSnakFormatter::$formattersByDataType
private

◆ $formattersBySnakType

Wikibase\Lib\Formatters\DispatchingSnakFormatter::$formattersBySnakType
private

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