violations = $violations; $this->message = $message; $this->parameters = $parameters; $this->root = $root; $this->propertyPath = $propertyPath; $this->invalidValue = $invalidValue; $this->translator = $translator; $this->translationDomain = $translationDomain; $this->constraint = $constraint; } /** * {@inheritdoc} */ public function atPath($path) { $this->propertyPath = PropertyPath::append($this->propertyPath, $path); return $this; } /** * {@inheritdoc} */ public function setParameter($key, $value) { $this->parameters[$key] = $value; return $this; } /** * {@inheritdoc} */ public function setParameters(array $parameters) { $this->parameters = $parameters; return $this; } /** * {@inheritdoc} */ public function setTranslationDomain($translationDomain) { $this->translationDomain = $translationDomain; return $this; } /** * {@inheritdoc} */ public function setInvalidValue($invalidValue) { $this->invalidValue = $invalidValue; return $this; } /** * {@inheritdoc} */ public function setPlural($number) { $this->plural = $number; return $this; } /** * {@inheritdoc} */ public function setCode($code) { $this->code = $code; return $this; } /** * {@inheritdoc} */ public function setCause($cause) { $this->cause = $cause; return $this; } /** * {@inheritdoc} */ public function addViolation() { if (null === $this->plural) { $translatedMessage = $this->translator->trans( $this->message, $this->parameters, $this->translationDomain ); } else { try { $translatedMessage = $this->translator->transChoice( $this->message, $this->plural, $this->parameters, $this->translationDomain# ); } catch (\InvalidArgumentException $e) { $translatedMessage = $this->translator->trans( $this->message, $this->parameters, $this->translationDomain ); } } $this->violations->add(new ConstraintViolation( $translatedMessage, $this->message, $this->parameters, $this->root, $this->propertyPath, $this->invalidValue, $this->plural, $this->code, $this->constraint, $this->cause )); } }