respect-validation/docs/rules/Consecutive.md
Henrique Moody 2610a380dc
Replace "LazyConsecutive" with "Consecutive"
With this and the Lazy rule, the LazyConsecutive lost its purpose.

While working on it, I did refactor the Domain rule a bit, but mainly to
check how this rule could behave.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-06 23:57:49 +01:00

1.2 KiB

Consecutive

  • Consecutive(Validatable $rule1, Validatable $rule2, Validatable ...$rule)

Validates the input against a series of rules until one fails.

This rule can be handy for getting the least error messages possible from a chain.

This rule can be helpful in combinations with Lazy. An excellent example is when you want to validate a country code and a subdivision code.

v::consecutive(
    v::key('countryCode', v::countryCode()),
    v::lazy(static fn($input) => v::key('subdivisionCode', v::subdivisionCode($input['countryCode']))),
)->validate($_POST);

You need a valid country code to create a SubdivisionCode, so it makes sense only to validate the subdivision code only if the country code is valid. In this case, you could also have used When, but you would then have to write v::key('countryCode', v::countryCode()) twice in your chain.

Categorization

  • Composite
  • Conditions
  • Nesting

Changelog

Version Description
3.0.0 Created

See also: