| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\ParamValidator; |
| 4 |
|
| 5 |
use Throwable; |
| 6 |
use UnexpectedValueException; |
| 7 |
use Wikimedia\Message\DataMessageValue; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class ValidationException extends UnexpectedValueException { |
| 17 |
|
| 18 |
|
| 19 |
protected $failureMessage; |
| 20 |
|
| 21 |
|
| 22 |
protected $paramName; |
| 23 |
|
| 24 |
|
| 25 |
protected $paramValue; |
| 26 |
|
| 27 |
|
| 28 |
protected $settings; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function __construct( |
| 39 |
DataMessageValue $failureMessage, $name, $value, $settings, ?Throwable $previous = null |
| 40 |
) { |
| 41 |
$this->failureMessage = $failureMessage; |
| 42 |
$this->paramName = $name; |
| 43 |
$this->paramValue = $value; |
| 44 |
$this->settings = $settings; |
| 45 |
|
| 46 |
|
| 47 |
$msg = "Validation of `$name` failed: " . $failureMessage->getCode(); |
| 48 |
$data = $failureMessage->getData(); |
| 49 |
if ( $data ) { |
| 50 |
$msg .= ' ' . json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
| 51 |
} |
| 52 |
parent::__construct( $msg, 0, $previous ); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public function getFailureMessage() { |
| 64 |
return $this->failureMessage; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function getParamName() { |
| 72 |
return $this->paramName; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public function getParamValue() { |
| 80 |
return $this->paramValue; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function getSettings() { |
| 88 |
return $this->settings; |
| 89 |
} |
| 90 |
|
| 91 |
} |