MediaWiki  master
ValidationException.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Throwable;
6 use UnexpectedValueException;
8 
15 class ValidationException extends UnexpectedValueException {
16 
18  protected $failureMessage;
19 
21  protected $paramName;
22 
24  protected $paramValue;
25 
27  protected $settings;
28 
36  public function __construct(
37  DataMessageValue $failureMessage, $name, $value, $settings, Throwable $previous = null
38  ) {
39  $this->failureMessage = $failureMessage;
40  $this->paramName = $name;
41  $this->paramValue = $value;
42  $this->settings = $settings;
43 
44  // Parent class needs some static English message.
45  $msg = "Validation of `$name` failed: " . $failureMessage->getCode();
46  $data = $failureMessage->getData();
47  if ( $data ) {
48  $msg .= ' ' . json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
49  }
50  parent::__construct( $msg, 0, $previous );
51  }
52 
61  public function getFailureMessage() {
62  return $this->failureMessage;
63  }
64 
69  public function getParamName() {
70  return $this->paramName;
71  }
72 
77  public function getParamValue() {
78  return $this->paramValue;
79  }
80 
85  public function getSettings() {
86  return $this->settings;
87  }
88 
89 }
Wikimedia\Message\DataMessageValue\getCode
getCode()
Get the message code.
Definition: DataMessageValue.php:59
Wikimedia\ParamValidator
Definition: Callbacks.php:3
Wikimedia\ParamValidator\ValidationException
Error reporting for ParamValidator.
Definition: ValidationException.php:15
Wikimedia\ParamValidator\ValidationException\$settings
array $settings
Definition: ValidationException.php:27
Wikimedia\ParamValidator\ValidationException\getParamName
getParamName()
Fetch the parameter name that failed validation.
Definition: ValidationException.php:69
Wikimedia\Message\DataMessageValue\getData
getData()
Get the message's structured data.
Definition: DataMessageValue.php:67
Wikimedia\ParamValidator\ValidationException\getParamValue
getParamValue()
Fetch the parameter value that failed validation.
Definition: ValidationException.php:77
Wikimedia\ParamValidator\ValidationException\getFailureMessage
getFailureMessage()
Fetch the validation failure message.
Definition: ValidationException.php:61
Wikimedia\ParamValidator\ValidationException\__construct
__construct(DataMessageValue $failureMessage, $name, $value, $settings, Throwable $previous=null)
Definition: ValidationException.php:36
Wikimedia\Message\DataMessageValue
Value object representing a message for i18n with alternative machine-readable data.
Definition: DataMessageValue.php:21
Wikimedia\ParamValidator\ValidationException\$failureMessage
DataMessageValue $failureMessage
Definition: ValidationException.php:18
Wikimedia\ParamValidator\ValidationException\$paramValue
mixed $paramValue
Definition: ValidationException.php:24
Wikimedia\ParamValidator\ValidationException\$paramName
string $paramName
Definition: ValidationException.php:21
Wikimedia\ParamValidator\ValidationException\getSettings
getSettings()
Fetch the settings array that failed validation.
Definition: ValidationException.php:85