/**
  * @param JsonSerializationVisitor     $visitor
  * @param ConstraintViolationInterface $violation
  * @return array
  */
 public function serializeToJson(JsonSerializationVisitor $visitor, ConstraintViolationInterface $violation)
 {
     $data = array('propertyPath' => $this->transformPropertyPath($violation->getPropertyPath()), 'message' => $violation->getMessage(), 'code' => $violation->getCode(), 'value' => $violation->getInvalidValue());
     if (null === $visitor->getRoot()) {
         $visitor->setRoot($data);
     }
     return $data;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function format(Param $param, ConstraintViolationInterface $violation)
 {
     return sprintf("%s parameter %s value '%s' violated a constraint (%s)", $param instanceof QueryParam ? 'Query' : 'Request', $param->getKey(), $violation->getInvalidValue(), $violation->getMessage());
 }
예제 #3
0
 /**
  * @param ConstraintViolationInterface|ConstraintViolation $error
  * @return array
  */
 private function getValidationErrorArray($error)
 {
     return ['i18nKey' => method_exists($error->getConstraint(), 'getI18nKey') ? $error->getConstraint()->getI18nKey() : get_class($error->getConstraint()), 'messageTemplate' => $error->getMessageTemplate(), 'plural' => $error->getPlural(), 'invalidValue' => $error->getInvalidValue(), 'parameters' => $error->getParameters(), 'message' => $error->getMessage(), 'path' => $error->getPropertyPath()];
 }
 /**
  * {@inheritdoc}
  */
 public function format(ParamInterface $param, ConstraintViolationInterface $violation)
 {
     return sprintf("Parameter %s value '%s' violated a constraint (%s)", $param->getName(), $violation->getInvalidValue(), $violation->getMessage());
 }
예제 #5
0
 /**
  * @param ConstraintViolationInterface $violation
  */
 public function violation(ConstraintViolationInterface $violation)
 {
     $this->violations[] = $violation;
     $this->logger->warning("DataTrans: validation warning, '{class}', '{property}', '{message}', '{invalidValue}'!", array('content' => get_class($violation->getRoot()), 'property' => $violation->getPropertyPath(), 'message' => $violation->getMessage(), 'invalidValue' => is_scalar($violation->getInvalidValue()) ? $violation->getInvalidValue() : '_object_'));
 }
 /**
  * @Serializer\Groups({"all", "debug"})
  * @Serializer\SerializedName("invalidValue")
  * @Serializer\VirtualProperty
  */
 public function getInvalidValue()
 {
     return $this->constraintViolation->getInvalidValue();
 }