MediaWiki master
StatusValue Class Reference

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

Inherited by MediaWiki\Permissions\PermissionStatus, and MediaWiki\Status\Status.

Public Member Functions

 __toString ()
 Returns a string representation of the status for debugging.
 
 error ( $message,... $parameters)
 Add an error, do not set fatal flag This can be used for non-fatal errors.
 
 fatal ( $message,... $parameters)
 Add an error and set OK to false, indicating that the operation as a whole was fatal.
 
 getErrors ()
 Get the list of errors.
 
 getErrorsByType ( $type)
 Returns a list of status messages of the given type.
 
 getValue ()
 
 hasMessage ( $message)
 Returns true if the specified message is present as a warning or error.
 
 hasMessagesExcept (... $messages)
 Returns true if any other message than the specified ones is present as a warning or error.
 
 isGood ()
 Returns whether the operation completed and didn't have any error or warnings.
 
 isOK ()
 Returns whether the operation completed.
 
 merge ( $other, $overwriteValue=false)
 Merge another status object into this one.
 
 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.
 
 setOK ( $ok)
 Change operation status.
 
 setResult ( $ok, $value=null)
 Change operation result.
 
 splitByErrorType ()
 Splits this StatusValue object into two new StatusValue objects, one which contains only the error messages, and one that contains the warnings, only.
 
 warning ( $message,... $parameters)
 Add a new warning.
 

Static Public Member Functions

static newFatal ( $message,... $parameters)
 Factory function for fatal errors.
 
static newGood ( $value=null)
 Factory function for good results.
 

Public Attributes

int $failCount = 0
 Counter for batch operations.
 
mixed $statusData
 arbitrary extra data about the operation
 
bool[] $success = []
 Map of (key => bool) to indicate success of each part of batch operations.
 
int $successCount = 0
 Counter for batch operations.
 
mixed $value
 

Protected Member Functions

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

Protected Attributes

array[] $errors = []
 
bool $ok = true
 

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.

Stability: newable
Stability: stable
to extend
Since
1.25

Definition at line 47 of file StatusValue.php.

Member Function Documentation

◆ __toString()

StatusValue::__toString ( )

Returns a string representation of the status for debugging.

This is fairly verbose and may change without notice.

Returns
string

Definition at line 425 of file StatusValue.php.

References $params, and isOK().

◆ error()

StatusValue::error (   $message,
  $parameters 
)

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

Parameters
string | MessageSpecifier | MessageValue$messageMessage key or object
mixed...$parameters
Returns
$this

Definition at line 267 of file StatusValue.php.

Referenced by fatal().

◆ fatal()

◆ getErrors()

◆ getErrorsByType()

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[]

Definition at line 328 of file StatusValue.php.

Referenced by ApiErrorFormatter_BackCompat\arrayFromStatus(), and ApiBase\dieStatus().

◆ getStatusArray()

StatusValue::getStatusArray (   $type = false)
protected

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

Access: internal
Only for use by Status.
Note
this handles RawMessage poorly
Parameters
string | bool$type
Returns
array[]

Definition at line 505 of file StatusValue.php.

◆ getValue()

StatusValue::getValue ( )

◆ hasMessage()

StatusValue::hasMessage (   $message)

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

Parameters
string | MessageSpecifier | MessageValue$messageMessage key or object to search for
Returns
bool

Definition at line 346 of file StatusValue.php.

References MessageSpecifier\getKey().

Referenced by ApiBase\dieStatus().

◆ hasMessagesExcept()

StatusValue::hasMessagesExcept (   $messages)

Returns true if any other message than the specified ones is present as a warning or error.

Parameters
string|MessageSpecifier|MessageValue...$messages Messages to search for.
Returns
bool

Definition at line 369 of file StatusValue.php.

◆ isGood()

◆ isOK()

StatusValue::isOK ( )

◆ merge()

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

Merge another status object into this one.

Parameters
StatusValue$other
bool$overwriteValueWhether to override the "value" member
Returns
$this

Definition at line 297 of file StatusValue.php.

Referenced by ScopedLock\factory(), and FileOpBatch\runParallelBatches().

◆ newFatal()

static StatusValue::newFatal (   $message,
  $parameters 
)
static

Factory function for fatal errors.

Parameters
string | MessageSpecifier$messageMessage key or object
mixed...$parameters
Returns
static

Definition at line 85 of file StatusValue.php.

◆ newGood()

static StatusValue::newGood (   $value = null)
static

Factory function for good results.

Parameters
mixed | null$value
Returns
static

Definition at line 97 of file StatusValue.php.

Referenced by LocalFileDeleteBatch\execute().

◆ replaceMessage()

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 | MessageValue | string$sourceMessage key or object to search for
MessageSpecifier | MessageValue | string$destReplacement message key or object
Returns
bool Return true if the replacement was done, false otherwise.

Definition at line 401 of file StatusValue.php.

References $source, and MessageSpecifier\getKey().

Referenced by ApiBase\addBlockInfoToStatus(), and ApiBase\dieStatus().

◆ setOK()

StatusValue::setOK (   $ok)

Change operation status.

Parameters
bool$ok
Returns
$this

Definition at line 175 of file StatusValue.php.

Referenced by MediaWiki\Status\Status\__set(), and ApiBase\dieStatus().

◆ setResult()

◆ splitByErrorType()

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
static[]

Reimplemented in MediaWiki\Status\Status.

Definition at line 114 of file StatusValue.php.

References getValue(), and isOK().

◆ warning()

StatusValue::warning (   $message,
  $parameters 
)

Add a new warning.

Parameters
string | MessageSpecifier | MessageValue$messageMessage key or object
mixed...$parameters
Returns
$this

Definition at line 249 of file StatusValue.php.

Member Data Documentation

◆ $errors

array [] StatusValue::$errors = []
protected
Access: internal
Only for use by Status. Use self::getErrors() (get full list), self::splitByErrorType() (get errors/warnings), or self::fatal(), self::error() or self::warning() (add error/warning).

Definition at line 61 of file StatusValue.php.

◆ $failCount

int StatusValue::$failCount = 0

Counter for batch operations.

Definition at line 73 of file StatusValue.php.

◆ $ok

bool StatusValue::$ok = true
protected
Access: internal
Only for use by Status. Use self::isOK() or self::setOK().

Definition at line 53 of file StatusValue.php.

◆ $statusData

mixed StatusValue::$statusData

arbitrary extra data about the operation

Definition at line 76 of file StatusValue.php.

◆ $success

bool [] StatusValue::$success = []

Map of (key => bool) to indicate success of each part of batch operations.

Definition at line 67 of file StatusValue.php.

◆ $successCount

int StatusValue::$successCount = 0

Counter for batch operations.

Definition at line 70 of file StatusValue.php.

◆ $value

mixed StatusValue::$value

Definition at line 64 of file StatusValue.php.

Referenced by MediaWiki\Status\Status\__set().


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