MediaWiki REL1_33
|
Generic operation result class Has warning/error list, boolean status and arbitrary value. More...
Public Member Functions | |
__toString () | |
error ( $message) | |
Add an error, do not set fatal flag This can be used for non-fatal errors. | |
fatal ( $message) | |
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. | |
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) | |
Add a new warning. | |
Static Public Member Functions | |
static | newFatal ( $message) |
Factory function for fatal errors. | |
static | newGood ( $value=null) |
Factory function for good results. | |
Public Attributes | |
int | $failCount = 0 |
Counter for batch operations. | |
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 Attributes | |
array[] | $errors = [] |
bool | $ok = true |
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.
Definition at line 42 of file StatusValue.php.
StatusValue::__toString | ( | ) |
StatusValue::error | ( | $message | ) |
Add an error, do not set fatal flag This can be used for non-fatal errors.
string | MessageSpecifier | $message | Message key or object |
Definition at line 191 of file StatusValue.php.
References errors.
StatusValue::fatal | ( | $message | ) |
Add an error and set OK to false, indicating that the operation as a whole was fatal.
string | MessageSpecifier | $message | Message key or object |
Definition at line 205 of file StatusValue.php.
References errors.
Referenced by Status\getMessage(), and Status\getWikiText().
StatusValue::getErrors | ( | ) |
Get the list of errors.
Each error is a (message:string or MessageSpecifier,params:array) map
Definition at line 148 of file StatusValue.php.
Referenced by Status\__get(), Status\getMessage(), Status\getStatusArray(), and Status\getWikiText().
StatusValue::getErrorsByType | ( | $type | ) |
Returns a list of status messages of the given type.
Each entry is a map of:
string | $type |
Definition at line 240 of file StatusValue.php.
StatusValue::getValue | ( | ) |
Definition at line 137 of file StatusValue.php.
References $value.
Referenced by SearchEngine\maybePaginate(), UserPasswordPolicyTest\testCheckUserPassword(), and MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testProviderAllowsAuthenticationDataChange().
StatusValue::hasMessage | ( | $message | ) |
Returns true if the specified message is present as a warning or error.
string | MessageSpecifier | $message | Message key or object to search for |
Definition at line 258 of file StatusValue.php.
StatusValue::isGood | ( | ) |
Returns whether the operation completed and didn't have any error or warnings.
Definition at line 121 of file StatusValue.php.
Referenced by SpecialEmailUser\sendEmailForm(), HTMLForm\show(), EmailConfirmation\showRequestForm(), and UserPasswordPolicyTest\testCheckUserPassword().
StatusValue::isOK | ( | ) |
Returns whether the operation completed.
Definition at line 130 of file StatusValue.php.
Referenced by Status\__get(), __toString(), Status\getMessage(), Status\getWikiText(), and UserPasswordPolicyTest\testCheckUserPassword().
StatusValue::merge | ( | $other, | |
$overwriteValue = false |
|||
) |
Merge another status object into this one.
StatusValue | $other | |
bool | $overwriteValue | Whether to override the "value" member |
Definition at line 220 of file StatusValue.php.
References errors.
|
static |
Factory function for fatal errors.
string | MessageSpecifier | $message | Message key or object |
Definition at line 68 of file StatusValue.php.
References $params.
|
static |
Factory function for good results.
mixed | null | $value |
Definition at line 81 of file StatusValue.php.
References $value.
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.
MessageSpecifier | string | $source | Message key or object to search for |
MessageSpecifier | string | $dest | Replacement message key or object |
Definition at line 286 of file StatusValue.php.
StatusValue::setOK | ( | $ok | ) |
Change operation status.
bool | $ok |
Definition at line 157 of file StatusValue.php.
Referenced by Status\__set().
StatusValue::setResult | ( | $ok, | |
$value = null |
|||
) |
Change operation result.
bool | $ok | Whether the operation completed |
mixed | null | $value |
Definition at line 167 of file StatusValue.php.
References $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 ]
Reimplemented in Status.
Definition at line 98 of file StatusValue.php.
StatusValue::warning | ( | $message | ) |
Add a new warning.
string | MessageSpecifier | $message | Message key or object |
Definition at line 177 of file StatusValue.php.
References errors.
|
protected |
Definition at line 48 of file StatusValue.php.
Referenced by Status\getErrorMessageArray(), and Status\getWikiText().
int StatusValue::$failCount = 0 |
Counter for batch operations.
Definition at line 60 of file StatusValue.php.
|
protected |
Definition at line 45 of file StatusValue.php.
bool [] StatusValue::$success = [] |
Map of (key => bool) to indicate success of each part of batch operations.
Definition at line 54 of file StatusValue.php.
int StatusValue::$successCount = 0 |
Counter for batch operations.
Definition at line 57 of file StatusValue.php.
mixed StatusValue::$value |
Definition at line 51 of file StatusValue.php.