class CallbackValidator
Validator for Callback constraint.
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\ConstraintValidator implements \Symfony\Component\Validator\ConstraintValidatorInterface
- class \Symfony\Component\Validator\Constraints\CallbackValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of CallbackValidator
File
-
vendor/
symfony/ validator/ Constraints/ CallbackValidator.php, line 24
Namespace
Symfony\Component\Validator\ConstraintsView source
class CallbackValidator extends ConstraintValidator {
public function validate(mixed $object, Constraint $constraint) : void {
if (!$constraint instanceof Callback) {
throw new UnexpectedTypeException($constraint, Callback::class);
}
$method = $constraint->callback;
if ($method instanceof \Closure) {
$method($object, $this->context, $constraint->payload);
}
elseif (\is_array($method)) {
if (!\is_callable($method)) {
if (isset($method[0]) && \is_object($method[0])) {
$method[0] = $method[0]::class;
}
throw new ConstraintDefinitionException(json_encode($method) . ' targeted by Callback constraint is not a valid callable.');
}
$method($object, $this->context, $constraint->payload);
}
elseif (null !== $object) {
if (!method_exists($object, $method)) {
throw new ConstraintDefinitionException(\sprintf('Method "%s" targeted by Callback constraint does not exist in class "%s".', $method, get_debug_type($object)));
}
$reflMethod = new \ReflectionMethod($object, $method);
if ($reflMethod->isStatic()) {
$reflMethod->invoke(null, $object, $this->context, $constraint->payload);
}
else {
$reflMethod->invoke($object, $this->context, $constraint->payload);
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
CallbackValidator::validate | public | function | Checks if the passed value is valid. | Overrides ConstraintValidatorInterface::validate |
ConstraintValidator::$context | protected | property | ||
ConstraintValidator::formatTypeOf | protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator::formatValue | protected | function | Returns a string representation of the value. | |
ConstraintValidator::formatValues | protected | function | Returns a string representation of a list of values. | |
ConstraintValidator::initialize | public | function | Initializes the constraint validator. | Overrides ConstraintValidatorInterface::initialize |
ConstraintValidator::OBJECT_TO_STRING | public | constant | Whether to cast objects with a "__toString()" method to strings. | |
ConstraintValidator::PRETTY_DATE | public | constant | Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s"). |