respect-validation/docs/validators/Circuit.md
Henrique Moody 81310cc4d9
Rename namespace Rules to Validators
Since that namespace contains our “validators”, naming it as such makes
much more sense.
2026-01-05 17:36:35 +01:00

1.5 KiB

Circuit

  • Circuit(Validator $validator1, Validator $validator2, Validator ...$validator)

Validates the input against a series of validators until the first fails.

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

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

v::circuit(
    v::key('countryCode', v::countryCode()),
    v::lazy(static fn($input) => v::key('subdivisionCode', v::subdivisionCode($input['countryCode']))),
)->isValid($_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.

Templates

This validator does not have any templates, because it will always return the result of the first validator that fails. When all the validators pass, it will return the result of the last validator of the circuit.

Categorization

  • Composite
  • Conditions
  • Nesting

Changelog

Version Description
3.0.0 Created

See also: