4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Violation;
14 @trigger_error('The '.__NAMESPACE__.'\LegacyConstraintViolationBuilder class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
16 use Symfony\Component\Validator\ExecutionContextInterface;
19 * Backwards-compatible implementation of {@link ConstraintViolationBuilderInterface}.
21 * @author Bernhard Schussek <bschussek@gmail.com>
23 * @internal You should not instantiate or use this class. Code against
24 * {@link ConstraintViolationBuilderInterface} instead.
26 * @deprecated since version 2.5.5, to be removed in 3.0.
28 class LegacyConstraintViolationBuilder implements ConstraintViolationBuilderInterface
31 * @var ExecutionContextInterface
48 private $invalidValue;
53 private $propertyPath;
65 public function __construct(ExecutionContextInterface $context, $message, array $parameters)
67 $this->context = $context;
68 $this->message = $message;
69 $this->parameters = $parameters;
70 $this->invalidValue = $context->getValue();
76 public function atPath($path)
78 $this->propertyPath = $path;
86 public function setParameter($key, $value)
88 $this->parameters[$key] = $value;
96 public function setParameters(array $parameters)
98 $this->parameters = $parameters;
106 public function setTranslationDomain($translationDomain)
108 // can't be set in the old API
116 public function setInvalidValue($invalidValue)
118 $this->invalidValue = $invalidValue;
126 public function setPlural($number)
128 $this->plural = $number;
136 public function setCode($code)
146 public function setCause($cause)
148 // do nothing - we can't save the cause through the old API
156 public function addViolation()
158 if ($this->propertyPath) {
159 $this->context->addViolationAt($this->propertyPath, $this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
164 $this->context->addViolation($this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);