/**
  * {@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 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 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;
 }