/** * {@inheritdoc} */ public function validate($value, AbstractConstraint $constraint) { if (!$constraint instanceof NotBlank) { throw new UnexpectedConstraint($constraint, $this); } if (empty($value)) { return new Violation($value, $constraint->getMessage(), array('attribute' => 'This field')); } return null; }
/** * {@inheritdoc} */ public function validate($value, AbstractConstraint $constraint) { if (!$constraint instanceof Regex) { throw new UnexpectedConstraint($constraint, $this); } if (null !== $value && !preg_match('#' . $constraint->getPattern() . '#', $value)) { return new Violation($value, $constraint->getMessage(), array('attribute' => 'This field', 'value' => $value)); } return null; }
/** * {@inheritdoc} */ public function validate($value, AbstractConstraint $constraint) { if (!$constraint instanceof Email) { throw new UnexpectedConstraint($constraint, $this); } if (false === empty($value) && false === filter_var($value, FILTER_VALIDATE_EMAIL)) { return new Violation($value, $constraint->getMessage(), array('attribute' => 'This field')); } return null; }
/** * {@inheritdoc} */ public function validate($value, AbstractConstraint $constraint) { if (!$constraint instanceof Type) { throw new UnexpectedConstraint($constraint, $this); } $type = gettype($value); if (null !== $value && $type !== $constraint->getType()) { return new Violation($value, $constraint->getMessage(), array('attribute' => 'This field', 'type' => $type)); } return null; }
/** * Validate value by constraint. * * @param mixed $value * @param AbstractConstraint $constraint * @param array $parameters */ public function validate($value, AbstractConstraint $constraint, array $parameters = array()) { $validators = (array) $constraint->getValidatorClass(); foreach ($validators as $validator) { /** @var ValidatorInterface $validator */ $validator = new $validator(); if (null !== ($violation = $validator->validate($value, $constraint))) { $violation->addParameter($parameters); $this->violations[] = $violation; } } $this->errors = null; }