Final Class Yiisoft\Validator\Exception\InvalidCallbackReturnTypeException
| Inheritance | Yiisoft\Validator\Exception\InvalidCallbackReturnTypeException » Exception |
|---|---|
| Implements | Yiisoft\FriendlyException\FriendlyExceptionInterface |
An exception used by the handler ({@see CallbackHandler}) of {@see Callback} rule for the cases when returned value is not a {@see Result} instance.
Public Methods
Method Details
| public mixed __construct ( mixed $returnValue, integer $code = 0, ?\Throwable $previous = null ) | ||
| $returnValue | mixed | |
| $code | integer | |
| $previous | ?\Throwable | |
public function __construct(
/**
* @var mixed The actual wrong value returned from a callback.
*/
mixed $returnValue,
/**
* @var int The Exception code.
*/
int $code = 0,
/**
* @var Throwable|null The previous throwable used for the exception chaining.
*/
?Throwable $previous = null,
) {
$message = sprintf(
'Return value of callback must be an instance of "%s", "%s" returned.',
Result::class,
get_debug_type($returnValue),
);
parent::__construct($message, $code, $previous);
}
| public string getName ( ) | ||
| return | string |
Human understandable exception name. |
|---|---|---|
public function getName(): string
{
return 'Invalid callable return value';
}
| public string|null getSolution ( ) | ||
| return | string|null |
Suggestion on how to fix the exception. |
|---|---|---|
public function getSolution(): ?string
{
return <<<SOLUTION
callback must return an instance of `\Yiisoft\Validator\Result`. An example of a valid callback:
hp
Yiisoft\Validator\Result;
ic function (mixed \$value): Result
\$result = new Result();
if (!in_array(\$value, [7, 42], true)) {
\$result->addError('Value must be 7 or 42.');
}
return \$result;
TION;
}
Signup or Login in order to comment.