MediaWiki  1.27.2
StatusValue Class Reference

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
 

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

Definition at line 42 of file StatusValue.php.

Member Function Documentation

StatusValue::__toString ( )
Returns
string

Definition at line 269 of file StatusValue.php.

References $key, $out, $params, $status, as, errors, and isOK().

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

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.

Parameters
string | MessageSpecifier$messageMessage 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

Returns
array

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:

  • message: string message key or MessageSpecifier
  • params: array list of parameters
Parameters
string$type
Returns
array

Definition at line 207 of file StatusValue.php.

References $type, as, and errors.

StatusValue::getValue ( )
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

Definition at line 225 of file StatusValue.php.

References as, and errors.

StatusValue::isGood ( )

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

Returns
bool

Definition at line 88 of file StatusValue.php.

References $errors.

StatusValue::isOK ( )

Returns whether the operation completed.

Returns
bool

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.

Parameters
StatusValue$otherOther StatusValue object
bool$overwriteValueWhether to override the "value" member

Definition at line 187 of file StatusValue.php.

References errors.

static StatusValue::newFatal (   $message)
static

Factory function for fatal errors.

Parameters
string | MessageSpecifier$messageMessage key or object
Returns
StatusValue

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(), MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation(), and MediaWiki\Auth\LegacyHookPreAuthenticationProvider\testUserForCreation().

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

Factory function for good results.

Parameters
mixed$value
Returns
StatusValue

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.

Parameters
IStatusMessage | string$sourceMessage key or object to search for
IStatusMessage | string$destReplacement message key or object
Returns
bool Return true if the replacement was done, false otherwise.

Definition at line 253 of file StatusValue.php.

References $source, as, and errors.

StatusValue::setOK (   $ok)

Change operation status.

Parameters
bool$ok

Definition at line 124 of file StatusValue.php.

References $ok.

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

Change operation resuklt.

Parameters
bool$okWhether the operation completed
mixed$value

Definition at line 134 of file StatusValue.php.

References $ok, and $value.

StatusValue::warning (   $message)

Add a new warning.

Parameters
string | MessageSpecifier$messageMessage key or object

Definition at line 144 of file StatusValue.php.

References errors.

Member Data Documentation

array StatusValue::$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.

bool StatusValue::$ok = true
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().


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