Final Class Yiisoft\Validator\Error
| Inheritance | Yiisoft\Validator\Error |
|---|
A class representing validation error. It's added in a rule handler or via Yiisoft\Validator\Rule\Callback rule to the Yiisoft\Validator\Result to form the complete list of errors for a single validation.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Validator\Error | |
| getMessage() | A getter for $message property. Returns raw (non-translated) validation error message. | Yiisoft\Validator\Error |
| getMessageProcessing() | Returns error message processing type. | Yiisoft\Validator\Error |
| getParameters() | A getter for $parameters property. Returns parameters used for $message translation. | Yiisoft\Validator\Error |
| getValuePath() | A getter for $valuePath property. Returns a sequence of keys determining where a value caused the validation error is located within a nested structure. | Yiisoft\Validator\Error |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| MESSAGE_FORMAT | 1 | Yiisoft\Validator\Error | |
| MESSAGE_NONE | 0 | Yiisoft\Validator\Error | |
| MESSAGE_TRANSLATE | 2 | Yiisoft\Validator\Error |
Method Details
| public __construct( string|\Stringable $message, array $parameters = [], array $valuePath = [], integer $messageProcessing = self::MESSAGE_TRANSLATE ): mixed | ||
| $message | string|\Stringable |
The raw validation error message. Can be a simple text or a template with
placeholders enclosed in curly braces (
|
| $parameters | array |
Parameters used for $message translation - a mapping between parameter
names and values. Note that only scalar or |
| $valuePath | array |
A sequence of keys determining where a value caused the validation error is located within a nested structure. Examples of different value paths:
A value without nested structure won't have a path at all (it will be an empty array). |
| $messageProcessing | integer |
Message processing type:
|
public function __construct(
string|Stringable $message,
private readonly array $parameters = [],
private readonly array $valuePath = [],
private readonly int $messageProcessing = self::MESSAGE_TRANSLATE,
) {
$this->message = (string) $message;
}
A getter for $message property. Returns raw (non-translated) validation error message.
| public getMessage( ): string | ||
| return | string |
A simple text or a template used for translation. |
|---|---|---|
public function getMessage(): string
{
return $this->message;
}
Returns error message processing type.
| public getMessageProcessing( ): integer |
public function getMessageProcessing(): int
{
return $this->messageProcessing;
}
A getter for $parameters property. Returns parameters used for $message translation.
| public getParameters( ): array | ||
| return | array |
A mapping between parameter names and values. |
|---|---|---|
public function getParameters(): array
{
return $this->parameters;
}
A getter for $valuePath property. Returns a sequence of keys determining where a value caused the validation error is located within a nested structure.
| public getValuePath( string|null $escape = null ): array | ||
| $escape | string|null |
Symbol that will be escaped with a backslash char ( |
| return | array |
A list of keys for nested structures or an empty array otherwise. |
|---|---|---|
public function getValuePath(?string $escape = null): array
{
if ($escape === null) {
return $this->valuePath;
}
if (mb_strlen($escape) !== 1) {
throw new InvalidArgumentException('Escape symbol must be exactly one character.');
}
return array_map(
static fn($key): string => str_replace($escape, '\\' . $escape, (string) $key),
$this->valuePath,
);
}
Signup or Login in order to comment.