Semantic MediaWiki and related extensions
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SMW\MessageFormatter Class Reference

Public Member Functions

 __construct (Language $language)
 
 addFromKey ( $key)
 
 addFromArray (array $messages)
 
 getMessages ()
 
 setType ( $type)
 
 escape ( $escape)
 
 clear ()
 
 exists ()
 
 setLanguage (Language $language)
 
 getHtml ()
 
 getPlain ()
 

Static Public Member Functions

static newFromArray (Language $language, array $messages=[])
 

Protected Member Functions

 doFormat (array $messages)
 
 getString ( $html=true)
 

Protected Attributes

 $messages = []
 
 $type = 'warning'
 
 $separator = ' <!--br-->'
 
 $escape = true
 

Detailed Description

Class implementing message output formatting

GNU GPL v2+

Since
1.9
Author
mwjames This class is implementing message output formatting to avoid having classes to invoke a language object that is not a direct dependency (which means that context relevant information is mostly missing from the invoking class) therefore it is more appropriate to collect Message objects from the source and initiate an output formatting only when necessary and requested.

Constructor & Destructor Documentation

◆ __construct()

SMW\MessageFormatter::__construct ( Language  $language)
Since
1.9
Parameters
Language$language

Member Function Documentation

◆ addFromArray()

SMW\MessageFormatter::addFromArray ( array  $messages)

Adds an arbitrary array of messages which can either contain text or/and Message objects

Example:
$msgFormatter = new MessageFormatter( $language );
$msgFormatter->addFromArray( array( 'Foo', new Message( 'Bar' ) ) )->getHtml()
Since
1.9
Parameters
array$messages
Returns
MessageFormatter

◆ addFromKey()

SMW\MessageFormatter::addFromKey (   $key)

Creates a Message object from a key and adds it to an internal array

Since
1.9
Parameters
string$keymessage key
Returns
MessageFormatter

◆ clear()

SMW\MessageFormatter::clear ( )

Clears the internal message array

Since
1.9
Returns
MessageFormatter

◆ doFormat()

SMW\MessageFormatter::doFormat ( array  $messages)
protected

Formatting and normalization of an array

Note
The array is being recursively resolved in order to ensure that the returning representation is a 1-n array where duplicate entries have been eliminated already while Message objects being transformed into a simple text representation using the invoked language
Since
1.9
Parameters
array$messages
Returns
array

◆ escape()

SMW\MessageFormatter::escape (   $escape)

Enables/disables escaping for the output representation

Note
Escaping is generally enabled but in cases of special pages or with messages already being escaped this option can be circumvent by invoking escape( false )
Since
1.9
Parameters
boolean$escape
Returns
MessageFormatter

◆ exists()

SMW\MessageFormatter::exists ( )

Returns if the internal message array does contain messages

Since
1.9
Returns
boolean

◆ getHtml()

SMW\MessageFormatter::getHtml ( )

Returns html representation of the formatted messages

Since
1.9
Returns
string

◆ getMessages()

SMW\MessageFormatter::getMessages ( )

Returns unformatted invoked messages

Since
1.9
Returns
array

◆ getPlain()

SMW\MessageFormatter::getPlain ( )

Returns plain text representation of the formatted messages

Since
1.9
Returns
string

◆ getString()

SMW\MessageFormatter::getString (   $html = true)
protected

Converts the message array into a string representation

Since
1.9
Parameters
boolean$escape
boolean$html
Returns
string

◆ newFromArray()

static SMW\MessageFormatter::newFromArray ( Language  $language,
array  $messages = [] 
)
static

Convenience factory method to invoke a message array together with a language object

Example:
MessageFormatter::newFromArray( $language, array( 'Foo' ) )->getHtml();
Since
1.9
Parameters
Language$language
array | null$messages
Returns
MessageFormatter

◆ setLanguage()

SMW\MessageFormatter::setLanguage ( Language  $language)

Overrides invoked language object

Since
1.9
Parameters
Language$language
Returns
MessageFormatter

◆ setType()

SMW\MessageFormatter::setType (   $type)

Used in connection with the html output to invoke a specific display type

See also
Highlighter::getTypeId
Since
1.9
Returns
MessageFormatter

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

About | General disclaimer | Privacy policy