Callback
class Callback extends Constraint implements ValidatesOne (View source)
Validates any data using a callback function.
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
Callback 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.
Validates the given value and returns the validation result.
Details
__construct(string|array $callback, string|null $message = null, Strategy $strategy = Strategy::FailLazy)
Callback 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.