BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
Status Class Reference
Inheritance diagram for Status:

Public Member Functions

 __construct (StatusValue $sv=null)
 
 setResult ($ok, $value=null)
 
 getStatusValue ()
 
 isGood ()
 
 isOK ()
 
 warning ($message)
 
 error ($message)
 
 fatal ($message)
 
 getWikiText ($shortContext=false, $longContext=false, $lang=null)
 
 getMessage ($shortContext=false, $longContext=false, $lang=null)
 
 getHTML ($shortContext=false, $longContext=false, $lang=null)
 
 merge ($other, $overwriteValue=false)
 
 getErrorsArray ()
 
 getWarningsArray ()
 
 getErrorsByType ($type)
 
 hasMessage ($message)
 
 replaceMessage ($source, $dest)
 
 getValue ()
 
 __get ($name)
 
 __set ($name, $value)
 
 __toString ()
 
 __sleep ()
 
 __wakeup ()
 

Static Public Member Functions

static wrap ($sv)
 
static newFatal ($message)
 
static newGood ($value=null)
 

Public Attributes

 $value
 
 $success = []
 
 $successCount = 0
 
 $failCount = 0
 
 $cleanCallback = false
 

Protected Member Functions

 cleanParams (array $params)
 
 languageFromParam ($lang)
 
 getErrorMessage ($error, $lang=null)
 
 getErrorMessageArray ($errors, $lang=null)
 
 getStatusArray ($type=false)
 

Protected Attributes

 $sv
 

Detailed Description

Generic operation result class Has warning/error list, boolean status and arbitrary value

"Good" means the operation was completed with no warnings or errors.

"OK" means the operation was partially or wholly completed.

An operation which is not OK should have errors so that the user can be informed as to what went wrong. Calling the fatal() function sets an error message and simultaneously switches off the OK flag.

The recommended pattern for Status objects is to return a Status object unconditionally, i.e. both on success and on failure – so that the developer of the calling code is reminded that the function can fail, and so that a lack of error-handling will be explicit.

Constructor & Destructor Documentation

Status::__construct ( StatusValue  $sv = null)
Parameters
StatusValue$sv[optional]

Member Function Documentation

Status::__get (   $name)

Backwards compatibility logic

Parameters
string$name
Status::__set (   $name,
  $value 
)

Backwards compatibility logic

Parameters
string$name
mixed$value
Status::__sleep ( )

Don't save the callback when serializing, because Closures can't be serialized and we're going to clear it in __wakeup anyway.

Status::__toString ( )
Returns
string
Status::__wakeup ( )

Sanitize the callback parameter on wakeup, to avoid arbitrary execution.

Status::cleanParams ( array  $params)
protected
Parameters
array$params
Returns
array
Status::error (   $message)

Add an error, do not set fatal flag This can be used for non-fatal errors

Parameters
string | Message$messageMessage name or object
Status::fatal (   $message)

Add an error and set OK to false, indicating that the operation as a whole was fatal

Parameters
string | Message$messageMessage name or object
Status::getErrorMessage (   $error,
  $lang = null 
)
protected

Return the message for a single error.

Parameters
mixed$errorWith an array & two values keyed by 'message' and 'params', use those keys-value pairs. Otherwise, if its an array, just use the first value as the message and the remaining items as the params.
string | Language$langLanguage to use for processing messages
Returns
Message
Status::getErrorMessageArray (   $errors,
  $lang = null 
)
protected

Return an array with a Message object for each error.

Parameters
array$errors
string | Language$langLanguage to use for processing messages
Returns
Message[]
Status::getErrorsArray ( )

Get the list of errors (but not warnings)

Returns
array A list in which each entry is an array with a message key as its first element. The remaining array elements are the message parameters.
Deprecated:
1.25
Status::getErrorsByType (   $type)

Returns a list of status messages of the given type, with message and params left untouched, like a sane version of getStatusArray

Each entry is a map of:

  • message: string message key or MessageSpecifier
  • params: array list of parameters
Parameters
string$type
Returns
array
Status::getHTML (   $shortContext = false,
  $longContext = false,
  $lang = null 
)

Get the error message as HTML. This is done by parsing the wikitext error message.

Parameters
string$shortContextA short enclosing context message name, to be used when there is a single error
string$longContextA long enclosing context message name, for a list
string | Language$langLanguage to use for processing messages
Returns
string
Status::getMessage (   $shortContext = false,
  $longContext = false,
  $lang = null 
)

Get a bullet list of the errors as a Message object.

$shortContext and $longContext can be used to wrap the error list in some text. $shortContext will be preferred when there is a single error; $longContext will be preferred when there are multiple ones. In either case, $1 will be replaced with the list of errors.

$shortContext is assumed to use $1 as an inline parameter: if there is a single item, it will not be made into a list; if there are multiple items, newlines will be inserted around the list. $longContext is assumed to use $1 as a standalone parameter; it will always receive a list.

If both parameters are missing, and there is only one error, no bullet will be added.

Parameters
string|string[]$shortContext A message name or an array of message names.
string|string[]$longContext A message name or an array of message names.
string | Language$langLanguage to use for processing messages
Returns
Message
Status::getStatusArray (   $type = false)
protected

Returns a list of status messages of the given type (or all if false)

Note
: this handles RawMessage poorly
Parameters
string | bool$type
Returns
array
Status::getStatusValue ( )

Returns the wrapped StatusValue object

Returns
StatusValue
Status::getValue ( )
Returns
mixed
Status::getWarningsArray ( )

Get the list of warnings (but not errors)

Returns
array A list in which each entry is an array with a message key as its first element. The remaining array elements are the message parameters.
Deprecated:
1.25
Status::getWikiText (   $shortContext = false,
  $longContext = false,
  $lang = null 
)

Get the error list as a wikitext formatted list

Parameters
string | bool$shortContextA short enclosing context message name, to be used when there is a single error
string | bool$longContextA long enclosing context message name, for a list
string | Language$langLanguage to use for processing messages
Returns
string
Status::hasMessage (   $message)

Returns true if the specified message is present as a warning or error

Parameters
string | Message$messageMessage key or object to search for
Returns
bool
Status::isGood ( )

Returns whether the operation completed and didn't have any error or warnings

Returns
bool
Status::isOK ( )

Returns whether the operation completed

Returns
bool
Status::languageFromParam (   $lang)
protected
Parameters
string | Language | null$langLanguage to use for processing messages, or null to default to the user language.
Returns
Language
Status::merge (   $other,
  $overwriteValue = false 
)

Merge another status object into this one

Parameters
Status$otherOther Status object
bool$overwriteValueWhether to override the "value" member
static Status::newFatal (   $message)
static

Factory function for fatal errors

Parameters
string | Message$messageMessage name or object
Returns
Status
static Status::newGood (   $value = null)
static

Factory function for good results

Parameters
mixed$value
Returns
Status
Status::replaceMessage (   $source,
  $dest 
)

If the specified source message exists, replace it with the specified destination message, but keep the same parameters as in the original error.

Note, due to the lack of tools for comparing Message objects, this function will not work when using a Message object as the search parameter.

Parameters
Message | string$sourceMessage key or object to search for
Message | string$destReplacement message key or object
Returns
bool Return true if the replacement was done, false otherwise.
Status::setResult (   $ok,
  $value = null 
)

Change operation result

Parameters
bool$okWhether the operation completed
mixed$value
Status::warning (   $message)

Add a new warning

Parameters
string | Message$messageMessage name or object
static Status::wrap (   $sv)
static

Succinct helper method to wrap a StatusValue

This is is useful when formatting StatusValue objects:

$this->getOutput()->addHtml( Status::wrap( $sv )->getHTML() );
Parameters
StatusValue | Status$sv
Returns
Status

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