Constraint
class Constraint implements ValidatesAny (View source)
Validates any data using the passed validation expression.
Properties
protected array<string,string|null> | $messages | Constraint rules messages overrides. |
|
protected Strategy | $strategy | Constraint strategy. |
|
protected string | $validation | Constraint validation expression. |
|
protected Validator
Since: 1.2.0
|
$validator | Constraint validator instance. |
Methods
Constraint constructor.
Checks if the given value is valid and throws an exception if not.
Returns the master Validator instance that should be used in validation.
Gets constraint rules messages overrides.
Gets constraint strategy.
Gets constraint validation expression.
Gets constraint validator instance.
Checks if the given value is valid.
Sets constraint rules messages overrides.
Sets constraint strategy.
Sets constraint validation expression.
Validates the given value and returns the validation result.
Details
__construct(Validation $validation, array|null $messages = null, Strategy $strategy = Strategy::FailFast)
Constraint constructor.
void
check(mixed $value = null)
Checks if the given value is valid and throws an exception if not.
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.