Skip to content

Latest commit

 

History

History
54 lines (38 loc) · 1.43 KB

File metadata and controls

54 lines (38 loc) · 1.43 KB

Given

  • Given(Validator $when, Validator $then)

A conditional validator. When $when passes, validates $then; otherwise passes silently.

v::given(v::intVal(), v::positive())->assert(5);
// Validation passes successfully

v::given(v::intVal(), v::positive())->assert('non-integer');
// Validation passes successfully

v::given(v::intVal(), v::positive())->assert(-1);
// → -1 must be a positive number

In the sample above, if $input is an integer, then it must be positive. If $input is not an integer, validation passes silently — there is no $else branch.

This makes Given ideal inside AllOf or ShortCircuit chains where "skip when irrelevant" is the desired behavior.

Template placeholders

Placeholder Description
subject The validated input or the custom validator name (if specified).

Categorization

  • Conditions
  • Nesting

Changelog

Version Description
3.2.0 Created

See Also