mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
Version 3.0 will include a few crucial deprecations. This commit adds some soft deprecations to warn users about these changes. Some of the biggest changes are: * The method `validate()` will be renamed to `isValid()`. * The method `validate()` will be repurposed to return an object with failures. * It won't be possible to handle rules directly; users will need to use the `Validator` class to validate with any rule. There will some more changes, but those are some of the most important ones, and are the ones that are easy to deprecate right now.
1.1 KiB
1.1 KiB
Sorted
Sorted(string $direction)
Validates whether the input is sorted in a certain order or not.
v::sorted('ASC')->isValid([1, 2, 3]); // true
v::sorted('ASC')->isValid('ABC'); // true
v::sorted('DESC')->isValid([3, 2, 1]); // true
v::sorted('ASC')->isValid([]); // true
v::sorted('ASC')->isValid([1]); // true
You can also combine Call to create custom validations:
v::call(
static function (array $input): array {
return array_column($input, 'key');
},
v::sorted('ASC')
)->isValid([
['key' => 1],
['key' => 5],
['key' => 9],
]); // true
v::call('strval', v::sorted('DESC'))->isValid(4321); // true
v::call('iterator_to_array', v::sorted())->isValid(new ArrayIterator([1, 7, 4])); // false
Categorization
- Arrays
- Strings
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Add support for strings |
| 2.0.0 | Do not use array keys to sort |
| 2.0.0 | Use sorting direction instead of boolean value |
| 2.0.0 | Do not accept callback in the constructor |
| 1.1.1 | Created |
See also: