Validates every element of an array
, or object implementing \Traversable
, with a given set of rules.
EachValue(
Validator $validator,
?string $message = null
);
Validator::eachValue(
Validator::type('int')->range(1, 10)
)->validate([4, 5, 6]); // true
Validator::eachValue(
Validator::type('int')->range(1, 10)
)->validate([4, 5, 20]); // false
Note
An UnexpectedValueException
will be thrown when the input value is not an array
or an object implementing \Traversable
.
type: Validator
required
Validator that will validate each element of an array
or object implementing \Traversable
.
type: ?string
default: At key "{{ key }}": {{ message }}
Message that will be shown if at least one input value element is invalid according to the given validator
.
// throws: At key 2: The color value should not be blank.
Validator::eachValue(
Validator::notBlank()
)->assert(['red', 'green', ''], 'color');
The following parameters are available:
Parameter | Description |
---|---|
{{ value }} |
The current invalid value |
{{ name }} |
Name of the invalid value |
{{ key }} |
The key of the invalid iterable element |
{{ element }} |
The value of the invalid iterable element |
{{ message }} |
The rule message of the invalid iterable element |
0.4.0
Created