Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 50087e2

Browse files
committed
feat: added All rule documentation
1 parent c922cd7 commit 50087e2

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

docs/03-rules-all.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## All
2+
3+
Validates every element of an `array` with a set of rules.
4+
5+
## Basic Usage
6+
7+
```php
8+
Validator::all([Validator::greatarThan(1), Validator::lessThan(10)])->validate([4, 5, 6]); // true
9+
Validator::all([Validator::greaterThan(1)->lessThan(10)])->validate([4, 5, 6]); // true
10+
11+
Validator::all([Validator::greatarThan(1), Validator::lessThan(10)])->validate([4, 5, 20]); // false
12+
```
13+
14+
> **Note**
15+
> An `UnexpectedValueException` will be thrown if a `constraints` element does not implement a `RuleInterface`.
16+
17+
> **Note**
18+
> An `UnexpectedValueException` will be thrown when value to be validated is not an `array`.
19+
20+
## Options
21+
22+
### `constraints`
23+
24+
type: `array` `required`
25+
26+
Collection of rules, or validators, to validate each element of an `array`.
27+
Each element must implement a `RuleInterface`, so it is possible to use a single rule or a full validator set of rules.
28+
29+
### `message`
30+
31+
type: `string` default: `At "{{ key }}": {{ message }}`
32+
33+
Message that will be shown if at least one element of an array is invalid according to the given constraints.
34+
Check the [Custom Messages]() section for more information.
35+
36+
```php
37+
Validator::all([Validator::notBlank()])->assert([1, 2, ''], 'Test');
38+
// Throws: At "2": The "Test" value should not be blank, "" given.
39+
```
40+
41+
The following parameters are available:
42+
43+
| Parameter | Description |
44+
|-----------------|---------------------------------------|
45+
| `{{ value }}` | The current invalid array value |
46+
| `{{ name }}` | Name of the value being validated |
47+
| `{{ key }}` | The array key of the invalid value |
48+
| `{{ message }}` | The rule message of the invalid value |

docs/03-rules-range.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Validator::range(new DateTime('yesterday'), new DateTime('tomorrow'))->validate(
2626
> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information.
2727
2828
> **Note**
29-
> An `UnexpectedValueException` will be thrown when trying to compare incomparable values, like a `string` with an `int`
29+
> An `UnexpectedValueException` will be thrown when trying to compare incomparable values, like a `string` with an `int`.
3030
3131
> **Note**
3232
> An `UnexpectedValueException` will be thrown when the `minConstraint` value is greater than or equal to the `maxConstraint` value.

0 commit comments

Comments
 (0)