MediaWiki  1.34.0
Wikimedia\ParamValidator\ValidationException Class Reference

Error reporting for ParamValidator. More...

Inheritance diagram for Wikimedia\ParamValidator\ValidationException:
Collaboration diagram for Wikimedia\ParamValidator\ValidationException:

Public Member Functions

 __construct ( $name, $value, $settings, $code, $data, $previous=null)
 
 getFailureCode ()
 Fetch the validation failure code. More...
 
 getFailureData ()
 Fetch the validation failure data. More...
 
 getParamName ()
 Fetch the parameter name that failed validation. More...
 
 getParamValue ()
 Fetch the parameter value that failed validation. More...
 
 getSettings ()
 Fetch the settings array that failed validation. More...
 

Protected Attributes

string $failureCode
 
string int string[][] $failureData
 
string $paramName
 
mixed $paramValue
 
array $settings
 

Static Private Member Functions

static formatMessage ( $name, $code, $data)
 Make a simple English message for the exception. More...
 

Detailed Description

Error reporting for ParamValidator.

Since
1.34 @unstable

Definition at line 15 of file ValidationException.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\ParamValidator\ValidationException::__construct (   $name,
  $value,
  $settings,
  $code,
  $data,
  $previous = null 
)
Parameters
string$nameParameter name being validated
mixed$valueValue of the parameter
array$settingsSettings array being used for validation
string$codeFailure code. See getFailureCode() for requirements.
(string|int|string[])[]$data Data for the failure code. See getFailureData() for requirements.
Throwable | Exception | null$previousPrevious exception causing this failure

Definition at line 41 of file ValidationException.php.

References Wikimedia\ParamValidator\ValidationException\$settings.

Member Function Documentation

◆ formatMessage()

static Wikimedia\ParamValidator\ValidationException::formatMessage (   $name,
  $code,
  $data 
)
staticprivate

Make a simple English message for the exception.

Parameters
string$name
string$code
array$data
Returns
string

Definition at line 58 of file ValidationException.php.

◆ getFailureCode()

Wikimedia\ParamValidator\ValidationException::getFailureCode ( )

Fetch the validation failure code.

A validation failure code is a reasonably short string matching the regex /^[a-z][a-z0-9-]*$/.

Users are encouraged to use this with a suitable i18n mechanism rather than relying on the limited English text returned by getMessage().

Returns
string

Definition at line 104 of file ValidationException.php.

References Wikimedia\ParamValidator\ValidationException\$failureCode.

Referenced by MediaWiki\Rest\Validator\Validator\validateParams().

◆ getFailureData()

Wikimedia\ParamValidator\ValidationException::getFailureData ( )

Fetch the validation failure data.

This returns additional data relevant to the particular failure code.

Keys in the array are short ASCII strings. Values are strings or integers, or arrays of strings intended to be displayed as a comma-separated list. For any particular code the same keys are always returned in the same order, making it safe to use array_values() and access them positionally if that is desired.

For example, the data for a hypothetical "integer-out-of-range" code might have data ‘[ 'min’ => 0, 'max' => 100 ]` indicating the range of allowed values.

Returns
(string|int|string[])[]

Definition at line 125 of file ValidationException.php.

References Wikimedia\ParamValidator\ValidationException\$failureData.

Referenced by MediaWiki\Rest\Validator\Validator\validateParams().

◆ getParamName()

Wikimedia\ParamValidator\ValidationException::getParamName ( )

Fetch the parameter name that failed validation.

Returns
string

Definition at line 73 of file ValidationException.php.

References Wikimedia\ParamValidator\ValidationException\$paramName.

Referenced by MediaWiki\Rest\Validator\Validator\validateParams().

◆ getParamValue()

Wikimedia\ParamValidator\ValidationException::getParamValue ( )

Fetch the parameter value that failed validation.

Returns
mixed

Definition at line 81 of file ValidationException.php.

References Wikimedia\ParamValidator\ValidationException\$paramValue.

Referenced by MediaWiki\Rest\Validator\Validator\validateParams().

◆ getSettings()

Wikimedia\ParamValidator\ValidationException::getSettings ( )

Fetch the settings array that failed validation.

Returns
array

Definition at line 89 of file ValidationException.php.

References Wikimedia\ParamValidator\ValidationException\$settings.

Member Data Documentation

◆ $failureCode

string Wikimedia\ParamValidator\ValidationException::$failureCode
protected

◆ $failureData

string int string [][] Wikimedia\ParamValidator\ValidationException::$failureData
protected

◆ $paramName

string Wikimedia\ParamValidator\ValidationException::$paramName
protected

◆ $paramValue

mixed Wikimedia\ParamValidator\ValidationException::$paramValue
protected

◆ $settings

array Wikimedia\ParamValidator\ValidationException::$settings
protected

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