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

Public Member Functions

 splitByErrorType ()
 
 isGood ()
 
 isOK ()
 
 getValue ()
 
 getErrors ()
 
 setOK ($ok)
 
 setResult ($ok, $value=null)
 
 warning ($message)
 
 error ($message)
 
 fatal ($message)
 
 merge ($other, $overwriteValue=false)
 
 getErrorsByType ($type)
 
 hasMessage ($message)
 
 replaceMessage ($source, $dest)
 
 __toString ()
 

Static Public Member Functions

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

Public Attributes

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

Protected Attributes

 $ok = true
 
 $errors = []
 

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 StatusValue 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.

The use of Message objects should be avoided when serializability is needed.

Since
1.25

Member Function Documentation

StatusValue::__toString ( )
Returns
string
StatusValue::error (   $message)

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

Parameters
string | MessageSpecifier$messageMessage key or object
StatusValue::fatal (   $message)

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

Parameters
string | MessageSpecifier$messageMessage key or object
StatusValue::getErrors ( )

Get the list of errors

Each error is a (message:string or MessageSpecifier,params:array) map

Returns
array[]
StatusValue::getErrorsByType (   $type)

Returns a list of status messages of the given type

Each entry is a map of:

  • message: string message key or MessageSpecifier
  • params: array list of parameters
Parameters
string$type
Returns
array[]
StatusValue::getValue ( )
Returns
mixed
StatusValue::hasMessage (   $message)

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

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

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

Returns
bool
StatusValue::isOK ( )

Returns whether the operation completed

Returns
bool
StatusValue::merge (   $other,
  $overwriteValue = false 
)

Merge another status object into this one

Parameters
StatusValue$other
bool$overwriteValueWhether to override the "value" member
static StatusValue::newFatal (   $message)
static

Factory function for fatal errors

Parameters
string | MessageSpecifier$messageMessage key or object
Returns
static
static StatusValue::newGood (   $value = null)
static

Factory function for good results

Parameters
mixed$value
Returns
static
StatusValue::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 IStatusMessage objects, this function will not work when using such an object as the search parameter.

Parameters
MessageSpecifier | string$sourceMessage key or object to search for
MessageSpecifier | string$destReplacement message key or object
Returns
bool Return true if the replacement was done, false otherwise.
StatusValue::setOK (   $ok)

Change operation status

Parameters
bool$ok
StatusValue::setResult (   $ok,
  $value = null 
)

Change operation result

Parameters
bool$okWhether the operation completed
mixed$value
StatusValue::splitByErrorType ( )

Splits this StatusValue object into two new StatusValue objects, one which contains only the error messages, and one that contains the warnings, only. The returned array is defined as: [ 0 => object(StatusValue) # the StatusValue with error messages, only 1 => object(StatusValue) # The StatusValue with warning messages, only ]

Returns
StatusValue[]
StatusValue::warning (   $message)

Add a new warning

Parameters
string | MessageSpecifier$messageMessage key or object

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