ValidationRuleGroup
in package
implements
ValidationRule
Validation groups allow an application to use several different criteria to create complex validation schemes that would otherwise require writing complex rules or if statements.
Please note that it is encouraged to replace validation groups with custom rules that will yield higher code maintainability.
Tags
Interfaces, Classes and Traits
- ValidationRule
- Classes implementing this one indicate their ability to test a variable and verify that it's contents are according to what was expected.
Table of Contents
- TYPE_AND = 'and'
- The AND type implies that one failed validation will cause the entire group's return to be <i>failed</i>.
- TYPE_OR = 'or'
- When this is active, a rule passing means that messages will be discarded and the validation will be passed.
- $rules : array<string|int, ValidationRule>
- This array maintains the rules used to validate the data in this group.
- $type : string
- The type of the group. You may use AND rules inside of OR rules. Using AND without encapsulating them in an OR group is useless since the Validator uses AND by default.
- __construct() : mixed
- Creates a new validation group rule. These rules allow applications to validate complex scenarios - like types that need to be submitted matching a regex or a number.
- addRule() : ValidationRuleGroup
- Adds a new rule to the validation group. This can be another group, but nesting groups is heavily discouraged.
- iterateRules() : mixed
- setType() : ValidationRuleGroup
- Use one of the class constants TYPE_AND or TYPE_OR to select the behavior you wish to achieve in the validation rule.
- test() : bool|ValidationError
- Uses the rules provided to test whether the value provided matches the rules that were defined previously.
Constants
TYPE_AND
The AND type implies that one failed validation will cause the entire group's return to be <i>failed</i>.
public
mixed
TYPE_AND
= 'and'
TYPE_OR
When this is active, a rule passing means that messages will be discarded and the validation will be passed.
public
mixed
TYPE_OR
= 'or'
Properties
$rules
This array maintains the rules used to validate the data in this group.
private
array<string|int, ValidationRule>
$rules
= array()
$type
The type of the group. You may use AND rules inside of OR rules. Using AND without encapsulating them in an OR group is useless since the Validator uses AND by default.
private
string
$type
= self::TYPE_OR
Methods
__construct()
Creates a new validation group rule. These rules allow applications to validate complex scenarios - like types that need to be submitted matching a regex or a number.
public
__construct() : mixed
This scenarios are rare and should usually be implemented with custom rules.
Return values
mixed —addRule()
Adds a new rule to the validation group. This can be another group, but nesting groups is heavily discouraged.
public
addRule(ValidationRule $rule) : ValidationRuleGroup
Parameters
- $rule : ValidationRule
Return values
ValidationRuleGroup —iterateRules()
public
iterateRules(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —setType()
Use one of the class constants TYPE_AND or TYPE_OR to select the behavior you wish to achieve in the validation rule.
public
setType(string $type) : ValidationRuleGroup
Parameters
- $type : string
Return values
ValidationRuleGroup —test()
Uses the rules provided to test whether the value provided matches the rules that were defined previously.
public
test(mixed $value) : bool|ValidationError
Parameters
- $value : mixed