MediaWiki
master
|
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. More... | |
fatal ($message) | |
Add an error and set OK to false, indicating that the operation as a whole was fatal. More... | |
getErrors () | |
Get the list of errors. More... | |
getErrorsByType ($type) | |
Returns a list of status messages of the given type. More... | |
getValue () | |
hasMessage ($message) | |
Returns true if the specified message is present as a warning or error. More... | |
isGood () | |
Returns whether the operation completed and didn't have any error or warnings. More... | |
isOK () | |
Returns whether the operation completed. More... | |
merge ($other, $overwriteValue=false) | |
Merge another status object into this one. More... | |
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. More... | |
setOK ($ok) | |
Change operation status. More... | |
setResult ($ok, $value=null) | |
Change operation resuklt. More... | |
warning ($message) | |
Add a new warning. More... | |
Static Public Member Functions | |
static | newFatal ($message) |
Factory function for fatal errors. More... | |
static | newGood ($value=null) |
Factory function for good results. More... | |
Public Attributes | |
int | $failCount = 0 |
Counter for batch operations. More... | |
array | $success = [] |
Map of (key => bool) to indicate success of each part of batch operations. More... | |
int | $successCount = 0 |
Counter for batch operations. More... | |
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 158 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 172 of file StatusValue.php.
References errors.
StatusValue::getErrors | ( | ) |
Get the list of errors.
Each error is a (message:string or MessageSpecifier,params:array) map
Definition at line 115 of file StatusValue.php.
References $errors.
StatusValue::getErrorsByType | ( | $type | ) |
Returns a list of status messages of the given type.
Each entry is a map of:
string | $type |
Definition at line 207 of file StatusValue.php.
StatusValue::getValue | ( | ) |
Definition at line 104 of file StatusValue.php.
References $value.
Referenced by 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 225 of file StatusValue.php.
StatusValue::isGood | ( | ) |
Returns whether the operation completed and didn't have any error or warnings.
Definition at line 88 of file StatusValue.php.
References $errors.
StatusValue::isOK | ( | ) |
Returns whether the operation completed.
Definition at line 97 of file StatusValue.php.
References $ok.
Referenced by __toString().
StatusValue::merge | ( | $other, | |
$overwriteValue = false |
|||
) |
Merge another status object into this one.
StatusValue | $other | Other StatusValue object |
bool | $overwriteValue | Whether to override the "value" member |
Definition at line 187 of file StatusValue.php.
References errors.
|
static |
Factory function for fatal errors.
string | MessageSpecifier | $message | Message key or object |
Definition at line 63 of file StatusValue.php.
References $params.
Referenced by SpecialUnlinkAccounts\execute(), SpecialLinkAccounts\execute(), PasswordReset\execute(), PasswordReset\isAllowed(), MediaWiki\Auth\LegacyHookPreAuthenticationProvider\makeFailResponse(), MediaWiki\Auth\UserDataAuthenticationRequest\populateUser(), MediaWiki\Auth\AuthManagerTest\provideAccountCreation(), MediaWiki\Auth\AuthManagerTest\provideAccountLink(), MediaWiki\Auth\AuthManagerTest\provideAllowsAuthenticationDataChange(), MediaWiki\Auth\AuthManagerTest\provideAuthentication(), MediaWiki\Auth\UserDataAuthenticationRequestTest\providePopulateUser(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\AuthPluginPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\LegacyHookPreAuthenticationProviderTest\provideTestForAccountCreation(), SpecialLinkAccounts\success(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAccountCreationEmail(), MediaWiki\Auth\AuthManagerTest\testAutoAccountCreation(), MediaWiki\Auth\AuthManagerTest\testAutoCreateFailOnLogin(), MediaWiki\Auth\AuthManagerTest\testBeginAccountCreation(), MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProviderTest\testBeginLinkAttempt(), MediaWiki\Auth\AuthManagerTest\testCanCreateAccount(), MediaWiki\Auth\AuthManagerTest\testContinueAccountCreation(), MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProviderTest\testContinueLinkAttempt(), MediaWiki\Auth\LegacyHookPreAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\AuthManagerTest\testGetAuthenticationRequests(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationDataEmail(), MediaWiki\Auth\ThrottlePreAuthenticationProviderTest\testTestForAccountCreation(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testTestForAccountCreation(), MediaWiki\Auth\ResetPasswordSecondaryAuthenticationProviderTest\testTryReset(), and MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation().
|
static |
Factory function for good results.
mixed | $value |
Definition at line 76 of file StatusValue.php.
References $value.
Referenced by SpecialUnlinkAccounts\execute(), PasswordReset\execute(), PasswordReset\isAllowed(), MediaWiki\Auth\LegacyHookPreAuthenticationProvider\makeFailResponse(), MediaWiki\Auth\UserDataAuthenticationRequest\populateUser(), MediaWiki\Auth\AuthManagerTest\provideAccountCreation(), MediaWiki\Auth\AuthManagerTest\provideAccountLink(), MediaWiki\Auth\AuthManagerTest\provideAllowsAuthenticationDataChange(), MediaWiki\Auth\AuthManagerTest\provideAuthentication(), MediaWiki\Auth\UserDataAuthenticationRequestTest\providePopulateUser(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\AuthPluginPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider\providerAllowsAuthenticationDataChange(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\providerAllowsAuthenticationDataChange(), MediaWiki\Auth\AuthPluginPrimaryAuthenticationProvider\providerAllowsAuthenticationDataChange(), MediaWiki\Auth\LegacyHookPreAuthenticationProviderTest\provideTestForAccountCreation(), MediaWiki\Auth\AbstractPreAuthenticationProviderTest\testAbstractPreAuthenticationProvider(), MediaWiki\Auth\AbstractPrimaryAuthenticationProviderTest\testAbstractPrimaryAuthenticationProvider(), MediaWiki\Auth\AbstractSecondaryAuthenticationProviderTest\testAbstractSecondaryAuthenticationProvider(), MediaWiki\Auth\AuthManagerTest\testAccountCreation(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAccountCreationEmail(), MediaWiki\Auth\AuthManagerTest\testAccountCreationLogging(), MediaWiki\Auth\AuthManagerTest\testAccountLink(), MediaWiki\Auth\AuthManagerTest\testAuthentication(), MediaWiki\Auth\AuthManagerTest\testAutoAccountCreation(), MediaWiki\Auth\AuthManagerTest\testAutoCreateOnLogin(), MediaWiki\Auth\AuthManagerTest\testBeginAccountCreation(), MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProviderTest\testBeginLinkAttempt(), MediaWiki\Auth\AuthManagerTest\testCanCreateAccount(), MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProviderTest\testContinueLinkAttempt(), MediaWiki\Auth\ThrottlePreAuthenticationProviderTest\testDisabled(), MediaWiki\Auth\LegacyHookPreAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\testForAccountCreation(), MediaWiki\Auth\LegacyHookPreAuthenticationProvider\testForAuthentication(), MediaWiki\Auth\AuthManagerTest\testGetAuthenticationRequests(), MediaWiki\Auth\AuthManagerTest\testGetAuthenticationRequestsRequired(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testProviderAllowsAuthenticationDataChange(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationDataEmail(), MediaWiki\Auth\ThrottlePreAuthenticationProviderTest\testTestForAccountCreation(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testTestForAccountCreation(), MediaWiki\Auth\AuthPluginPrimaryAuthenticationProviderTest\testTestForAccountCreation(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testTestForAccountCreation(), MediaWiki\Auth\LegacyHookPreAuthenticationProviderTest\testTestForAuthentication(), MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProviderTest\testTestUserForCreation(), MediaWiki\Auth\LegacyHookPreAuthenticationProviderTest\testTestUserForCreation(), MediaWiki\Auth\ResetPasswordSecondaryAuthenticationProviderTest\testTryReset(), MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation(), and MediaWiki\Auth\LegacyHookPreAuthenticationProvider\testUserForCreation().
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.
IStatusMessage | string | $source | Message key or object to search for |
IStatusMessage | string | $dest | Replacement message key or object |
Definition at line 253 of file StatusValue.php.
StatusValue::setOK | ( | $ok | ) |
Change operation status.
bool | $ok |
Definition at line 124 of file StatusValue.php.
References $ok.
StatusValue::setResult | ( | $ok, | |
$value = null |
|||
) |
Change operation resuklt.
bool | $ok | Whether the operation completed |
mixed | $value |
Definition at line 134 of file StatusValue.php.
StatusValue::warning | ( | $message | ) |
Add a new warning.
string | MessageSpecifier | $message | Message key or object |
Definition at line 144 of file StatusValue.php.
References errors.
|
protected |
Definition at line 46 of file StatusValue.php.
Referenced by getErrors(), and isGood().
int StatusValue::$failCount = 0 |
Counter for batch operations.
Definition at line 55 of file StatusValue.php.
|
protected |
Definition at line 44 of file StatusValue.php.
Referenced by isOK(), setOK(), and setResult().
array StatusValue::$success = [] |
Map of (key => bool) to indicate success of each part of batch operations.
Definition at line 51 of file StatusValue.php.
int StatusValue::$successCount = 0 |
Counter for batch operations.
Definition at line 53 of file StatusValue.php.
mixed StatusValue::$value |
Definition at line 49 of file StatusValue.php.
Referenced by getValue(), newGood(), and setResult().