/** * @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; }
/** * Checks if the given violation is the appropriate one. * * @param ConstraintViolationInterface $violation * * @return bool */ private function isUniquePropertyViolation(ConstraintViolationInterface $violation) : bool { return UniqueProperty::NON_UNIQUE_PROPERTY === $violation->getCode() && 'username' === $violation->getPropertyPath(); // the username property is always `username` in the `CreateUserDTO` }
/** * @Serializer\Groups({"all", "debug"}) * @Serializer\SerializedName("invalidValue") * @Serializer\VirtualProperty */ public function getCode() { return $this->constraintViolation->getCode(); }