Final Class Yiisoft\Validator\Rule\UniqueIterable
Allows to define a set of rules for validating uniqueness of each element of an iterable.
See also Yiisoft\Validator\Rule\EachHandler Corresponding handler performing the actual validation.
Public Methods
Method Details
| public mixed __construct ( string $incorrectInputMessage = '{Property} must be array or iterable.', string $incorrectItemValueMessage = 'The allowed types for iterable\'s item values of {property} are ' . 'integer, float, string, boolean and object implementing \\Stringable or \\DateTimeInterface.', string $differentTypesMessage = 'All iterable items of {property} must have the same type.', string $message = 'Every iterable\'s item of {property} must be unique.', boolean|callable|null $skipOnEmpty = null, boolean $skipOnError = false, Closure|null $when = null ) | ||
| $incorrectInputMessage | string |
Error message used when validation fails because the validated value is not an iterable. You may use the following placeholders in the message:
|
| $incorrectItemValueMessage | string |
Error message used when validation fails because the validated iterable
contains items with invalid values. Only the following types are allowed: scalar (string, integer, float,
boolean), objects implementing You may use the following placeholders in the message:
|
| $differentTypesMessage | string |
Error message used when validation fails because the validated iterable contains items of different type. You may use the following placeholders in the message:
|
| $message | string |
Error message used when validation fails because the validated iterable contains duplicate items. You may use the following placeholders in the message:
|
| $skipOnEmpty | boolean|callable|null |
Whether to skip this |
| $skipOnError | boolean |
Whether to skip this |
| $when | Closure|null |
A callable to define a condition for applying this |
public function __construct(
private string $incorrectInputMessage = '{Property} must be array or iterable.',
private string $incorrectItemValueMessage = 'The allowed types for iterable\'s item values of {property} are '
. 'integer, float, string, boolean and object implementing \Stringable or \DateTimeInterface.',
private string $differentTypesMessage = 'All iterable items of {property} must have the same type.',
private string $message = 'Every iterable\'s item of {property} must be unique.',
bool|callable|null $skipOnEmpty = null,
private bool $skipOnError = false,
private ?Closure $when = null,
) {
$this->skipOnEmpty = $skipOnEmpty;
}
Error message used when validation fails because the validated iterable contains items of different types.
| public string getDifferentTypesMessage ( ) | ||
| return | string |
Error message / template. |
|---|---|---|
public function getDifferentTypesMessage(): string
{
return $this->differentTypesMessage;
}
| public string getHandler ( ) |
public function getHandler(): string
{
return UniqueIterableHandler::class;
}
Gets error message used when validation fails because the validated value is not an iterable.
| public string getIncorrectInputMessage ( ) | ||
| return | string |
Error message / template. |
|---|---|---|
public function getIncorrectInputMessage(): string
{
return $this->incorrectInputMessage;
}
Error message used when validation fails because the validated iterable contains items with invalid values.
| public string getIncorrectItemValueMessage ( ) | ||
| return | string |
Error message / template. |
|---|---|---|
public function getIncorrectItemValueMessage(): string
{
return $this->incorrectItemValueMessage;
}
Error message used when validation fails because the validated iterable contains duplicate items.
| public string getMessage ( ) | ||
| return | string |
Error message / template. |
|---|---|---|
public function getMessage(): string
{
return $this->message;
}
| public array getOptions ( ) |
#[ArrayShape([
'incorrectInputMessage' => 'array',
'incorrectItemValueMessage' => 'array',
'message' => 'array',
'skipOnEmpty' => 'bool',
'skipOnError' => 'bool',
])]
public function getOptions(): array
{
return [
'incorrectInputMessage' => [
'template' => $this->incorrectInputMessage,
'parameters' => [],
],
'incorrectItemValueMessage' => [
'template' => $this->incorrectItemValueMessage,
'parameters' => [],
],
'differentTypesMessage' => [
'template' => $this->differentTypesMessage,
'parameters' => [],
],
'message' => [
'template' => $this->message,
'parameters' => [],
],
'skipOnEmpty' => $this->getSkipOnEmptyOption(),
'skipOnError' => $this->skipOnError,
];
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::getSkipOnEmpty()
A getter for $skipOnEmpty property.
| public boolean|callable|null getSkipOnEmpty ( ) | ||
| return | boolean|callable|null |
A current raw (non-normalized) value. |
|---|---|---|
public function getSkipOnEmpty(): bool|callable|null
{
return $this->skipOnEmpty;
}
Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::getWhen()
A getter for $when property.
| public Closure|null getWhen ( ) | ||
| return | Closure|null |
Current value:
|
|---|---|---|
public function getWhen(): ?Closure
{
return $this->when;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::shouldSkipOnError()
A getter for $skipOnError property.
| public boolean shouldSkipOnError ( ) | ||
| return | boolean |
Current value. |
|---|---|---|
public function shouldSkipOnError(): bool
{
return $this->skipOnError;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::skipOnEmpty()
An immutable setter to change $skipOnEmpty property.
| public $this skipOnEmpty ( boolean|callable|null $value ) | ||
| $value | boolean|callable|null |
A new value. |
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function skipOnEmpty(bool|callable|null $value): static
{
$new = clone $this;
$new->skipOnEmpty = $value;
return $new;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::skipOnError()
An immutable setter to change $skipOnError property.
| public $this skipOnError ( boolean $value ) | ||
| $value | boolean |
A new value. |
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function skipOnError(bool $value): static
{
$new = clone $this;
$new->skipOnError = $value;
return $new;
}
Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::when()
An immutable setter to change $when property.
| public $this when ( Closure|null $value ) | ||
| $value | Closure|null |
A new value:
|
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function when(?Closure $value): static
{
$new = clone $this;
$new->when = $value;
return $new;
}
Signup or Login in order to comment.