|
| 1 | +# ContainsCount |
| 2 | + |
| 3 | +- `ContainsCount(mixed $containsValue, int $count)` |
| 4 | +- `ContainsCount(mixed $containsValue, int $count, bool $identical)` |
| 5 | + |
| 6 | +Validates if the input contains a value a specific number of times. |
| 7 | + |
| 8 | +For strings: |
| 9 | + |
| 10 | +```php |
| 11 | +v::containsCount('ipsum', 2)->assert('ipsum lorem ipsum'); |
| 12 | +// Validation passes successfully |
| 13 | +``` |
| 14 | + |
| 15 | +For arrays: |
| 16 | + |
| 17 | +```php |
| 18 | +v::containsCount('ipsum', 2)->assert(['ipsum', 'lorem', 'ipsum']); |
| 19 | +// Validation passes successfully |
| 20 | +``` |
| 21 | + |
| 22 | +A third parameter may be passed for identical comparison instead of equal comparison. |
| 23 | + |
| 24 | +```php |
| 25 | +v::containsCount(1, 1, true)->assert([1, 2, 3]); |
| 26 | +// Validation passes successfully |
| 27 | + |
| 28 | +v::containsCount('1', 1, true)->assert([1, 2, 3]); |
| 29 | +// → `[1, 2, 3]` must contain "1" 1 times |
| 30 | +``` |
| 31 | + |
| 32 | +## Templates |
| 33 | + |
| 34 | +### `ContainsCount::TEMPLATE_STANDARD` |
| 35 | + |
| 36 | +| Mode | Template | |
| 37 | +| ---------- | -------------------------------------------------------------- | |
| 38 | +| `default` | {{subject}} must contain {{containsValue}} {{count}} times | |
| 39 | +| `inverted` | {{subject}} must not contain {{containsValue}} {{count}} times | |
| 40 | + |
| 41 | +## Template placeholders |
| 42 | + |
| 43 | +| Placeholder | Description | |
| 44 | +| --------------- | ---------------------------------------------------------------- | |
| 45 | +| `containsValue` | | |
| 46 | +| `subject` | The validated input or the custom validator name (if specified). | |
| 47 | +| `count` | Number of times that the needle might appear in the haystack. | |
| 48 | + |
| 49 | +## Categorization |
| 50 | + |
| 51 | +- Arrays |
| 52 | +- Strings |
| 53 | + |
| 54 | +## Changelog |
| 55 | + |
| 56 | +| Version | Description | |
| 57 | +| ------: | ----------- | |
| 58 | +| 3.0.0 | Created | |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +See also: |
| 63 | + |
| 64 | +- [Contains](Contains.md) |
| 65 | +- [ContainsAny](ContainsAny.md) |
| 66 | +- [EndsWith](EndsWith.md) |
| 67 | +- [Equals](Equals.md) |
| 68 | +- [Equivalent](Equivalent.md) |
| 69 | +- [Identical](Identical.md) |
| 70 | +- [In](In.md) |
| 71 | +- [Regex](Regex.md) |
| 72 | +- [StartsWith](StartsWith.md) |
| 73 | +- [Unique](Unique.md) |
0 commit comments