MediaWiki  1.34.0
ValidationException.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Exception;
6 use Throwable;
7 use UnexpectedValueException;
8 
15 class ValidationException extends UnexpectedValueException {
16 
18  protected $paramName;
19 
21  protected $paramValue;
22 
24  protected $settings;
25 
27  protected $failureCode;
28 
30  protected $failureData;
31 
41  public function __construct( $name, $value, $settings, $code, $data, $previous = null ) {
42  parent::__construct( self::formatMessage( $name, $code, $data ), 0, $previous );
43 
44  $this->paramName = $name;
45  $this->paramValue = $value;
46  $this->settings = $settings;
47  $this->failureCode = $code;
48  $this->failureData = $data;
49  }
50 
58  private static function formatMessage( $name, $code, $data ) {
59  $ret = "Validation of `$name` failed: $code";
60  foreach ( $data as $k => $v ) {
61  if ( is_array( $v ) ) {
62  $v = implode( ', ', $v );
63  }
64  $ret .= "; $k => $v";
65  }
66  return $ret;
67  }
68 
73  public function getParamName() {
74  return $this->paramName;
75  }
76 
81  public function getParamValue() {
82  return $this->paramValue;
83  }
84 
89  public function getSettings() {
90  return $this->settings;
91  }
92 
104  public function getFailureCode() {
105  return $this->failureCode;
106  }
107 
125  public function getFailureData() {
126  return $this->failureData;
127  }
128 
129 }
Wikimedia\ParamValidator
Definition: Callbacks.php:3
Wikimedia\ParamValidator\ValidationException
Error reporting for ParamValidator.
Definition: ValidationException.php:15
Wikimedia\ParamValidator\ValidationException\$failureCode
string $failureCode
Definition: ValidationException.php:27
Wikimedia\ParamValidator\ValidationException\$settings
array $settings
Definition: ValidationException.php:24
Wikimedia\ParamValidator\ValidationException\getParamName
getParamName()
Fetch the parameter name that failed validation.
Definition: ValidationException.php:73
Wikimedia\ParamValidator\ValidationException\getParamValue
getParamValue()
Fetch the parameter value that failed validation.
Definition: ValidationException.php:81
Wikimedia\ParamValidator\ValidationException\__construct
__construct( $name, $value, $settings, $code, $data, $previous=null)
Definition: ValidationException.php:41
Wikimedia\ParamValidator\ValidationException\getFailureData
getFailureData()
Fetch the validation failure data.
Definition: ValidationException.php:125
Wikimedia\ParamValidator\ValidationException\getFailureCode
getFailureCode()
Fetch the validation failure code.
Definition: ValidationException.php:104
Wikimedia\ParamValidator\ValidationException\$paramValue
mixed $paramValue
Definition: ValidationException.php:21
Wikimedia\ParamValidator\ValidationException\$failureData
string int string[][] $failureData
Definition: ValidationException.php:30
Wikimedia\ParamValidator\ValidationException\formatMessage
static formatMessage( $name, $code, $data)
Make a simple English message for the exception.
Definition: ValidationException.php:58
Wikimedia\ParamValidator\ValidationException\$paramName
string $paramName
Definition: ValidationException.php:18
Wikimedia\ParamValidator\ValidationException\getSettings
getSettings()
Fetch the settings array that failed validation.
Definition: ValidationException.php:89