respect-validation/docs/rules/Length.md
Henrique Moody 9eafe52252
Refactor the Length rule
Currently, the Length rule does multiple things, yet it's limited.
Because it does many things, it's also confusing. Turning the Length
rule into a transformation allows for way more flexibility and clarity.

The syntax becomes more verbose, but I can solve that later by creating
a Transformer enables creating rules with the "length" as a prefix.

While making this change, I also removed the support for counting
objects and integers. I find that way too confusing.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-19 15:38:29 +01:00

1 KiB

Length

  • Length(Validatable $rule)

Validates the length of the given input against a given rule.

v::length(v::between(1, 5))->validate('abc'); // true

v::length(v::greaterThan(5))->validate('abcdef'); // true

v::length(v::lessThan(5))->validate('abc'); // true

This rule can be used to validate the length of strings, arrays, and objects that implement the Countable interface.

v::length(v::greaterThanOrEqual(3))->validate([1, 2, 3]); // true

v::length(v::equals(0))->validate(new SplPriorityQueue()); // true

Categorization

  • Comparisons
  • Transformations

Changelog

Version Description
3.0.0 Became a transformation
0.3.9 Created

See also: