Version 1
[yaffs-website] / vendor / symfony / validator / Violation / LegacyConstraintViolationBuilder.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Violation;
13
14 @trigger_error('The '.__NAMESPACE__.'\LegacyConstraintViolationBuilder class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
15
16 use Symfony\Component\Validator\ExecutionContextInterface;
17
18 /**
19  * Backwards-compatible implementation of {@link ConstraintViolationBuilderInterface}.
20  *
21  * @author Bernhard Schussek <bschussek@gmail.com>
22  *
23  * @internal You should not instantiate or use this class. Code against
24  *           {@link ConstraintViolationBuilderInterface} instead.
25  *
26  * @deprecated since version 2.5.5, to be removed in 3.0.
27  */
28 class LegacyConstraintViolationBuilder implements ConstraintViolationBuilderInterface
29 {
30     /**
31      * @var ExecutionContextInterface
32      */
33     private $context;
34
35     /**
36      * @var string
37      */
38     private $message;
39
40     /**
41      * @var array
42      */
43     private $parameters;
44
45     /**
46      * @var mixed
47      */
48     private $invalidValue;
49
50     /**
51      * @var string
52      */
53     private $propertyPath;
54
55     /**
56      * @var int|null
57      */
58     private $plural;
59
60     /**
61      * @var mixed
62      */
63     private $code;
64
65     public function __construct(ExecutionContextInterface $context, $message, array $parameters)
66     {
67         $this->context = $context;
68         $this->message = $message;
69         $this->parameters = $parameters;
70         $this->invalidValue = $context->getValue();
71     }
72
73     /**
74      * {@inheritdoc}
75      */
76     public function atPath($path)
77     {
78         $this->propertyPath = $path;
79
80         return $this;
81     }
82
83     /**
84      * {@inheritdoc}
85      */
86     public function setParameter($key, $value)
87     {
88         $this->parameters[$key] = $value;
89
90         return $this;
91     }
92
93     /**
94      * {@inheritdoc}
95      */
96     public function setParameters(array $parameters)
97     {
98         $this->parameters = $parameters;
99
100         return $this;
101     }
102
103     /**
104      * {@inheritdoc}
105      */
106     public function setTranslationDomain($translationDomain)
107     {
108         // can't be set in the old API
109
110         return $this;
111     }
112
113     /**
114      * {@inheritdoc}
115      */
116     public function setInvalidValue($invalidValue)
117     {
118         $this->invalidValue = $invalidValue;
119
120         return $this;
121     }
122
123     /**
124      * {@inheritdoc}
125      */
126     public function setPlural($number)
127     {
128         $this->plural = $number;
129
130         return $this;
131     }
132
133     /**
134      * {@inheritdoc}
135      */
136     public function setCode($code)
137     {
138         $this->code = $code;
139
140         return $this;
141     }
142
143     /**
144      * {@inheritdoc}
145      */
146     public function setCause($cause)
147     {
148         // do nothing - we can't save the cause through the old API
149
150         return $this;
151     }
152
153     /**
154      * {@inheritdoc}
155      */
156     public function addViolation()
157     {
158         if ($this->propertyPath) {
159             $this->context->addViolationAt($this->propertyPath, $this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
160
161             return;
162         }
163
164         $this->context->addViolation($this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
165     }
166 }