Compound
class Compound extends Constraint implements ValidatesOne (View source)
Validates any data by compining a set of constraints to build up a Validation Expression.
Properties
protected array<string,string|null> | $messages | Constraint rules messages overrides. |
from Constraint |
protected Strategy | $strategy | Constraint strategy. |
from Constraint |
protected string | $validation | Constraint validation expression. |
from Constraint |
protected Validator
Since: 1.2.0
|
$validator | Constraint validator instance. |
from Constraint |
Methods
Compound constructor.
Checks if the given value is valid and throws an exception if not.
No description
Returns the master Validator instance that should be used in validation.
Validates the given value and returns the validation result.
Details
__construct(array $constraints, Operator $operator = Operator::And, Behavior $behavior = Behavior::Normal, Strategy $strategy = Strategy::FailLazy)
Compound constructor.
void
check(mixed $value = null)
Checks if the given value is valid and throws an exception if not.
private array
combineConstraints(array $constraints, Operator $operator, Behavior $behavior)
No description
final static protected Validator
getMasterValidator()
Returns the master Validator instance that should be used in validation.
NOTE: All constraint share the same Validator. Always clone it to avoid any side effects.
FACT: The idea of master Validator is used to allow for better memory management and faster load times as the default Validator loads 200+ rules by default. Cloning will make a shallow copy resulting in reusing the same rules loaded by the master Validator.
array
getMessages()
Gets constraint rules messages overrides.
Strategy
getStrategy()
Gets constraint strategy.
string
getValidation()
Gets constraint validation expression.
Validator
getValidator()
Gets constraint validator instance.
This method returns a clone of the master Validator
if a Validator is not set explicitly via self::setValidator()
.
bool
isValid(mixed $value = null)
Checks if the given value is valid.
Constraint
setMessages(array $messages)
Sets constraint rules messages overrides.
Constraint
setStrategy(Strategy $strategy)
Sets constraint strategy.
Constraint
setValidation(string $validation)
Sets constraint validation expression.
Constraint
setValidator(Validator $validator)
Sets constraint validator instance.
Result
validate(mixed $value = null)
Validates the given value and returns the validation result.