Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/validator/Context/ExecutionContextInterface.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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\Context; | |
13 | |
14 use Symfony\Component\Validator\Constraint; | |
15 use Symfony\Component\Validator\Mapping; | |
16 use Symfony\Component\Validator\Mapping\MetadataInterface; | |
17 use Symfony\Component\Validator\Validator\ValidatorInterface; | |
18 use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; | |
19 use Symfony\Component\Validator\ConstraintViolationListInterface; | |
20 | |
21 /** | |
22 * The context of a validation run. | |
23 * | |
24 * The context collects all violations generated during the validation. By | |
25 * default, validators execute all validations in a new context: | |
26 * | |
27 * $violations = $validator->validate($object); | |
28 * | |
29 * When you make another call to the validator, while the validation is in | |
30 * progress, the violations will be isolated from each other: | |
31 * | |
32 * public function validate($value, Constraint $constraint) | |
33 * { | |
34 * $validator = $this->context->getValidator(); | |
35 * | |
36 * // The violations are not added to $this->context | |
37 * $violations = $validator->validate($value); | |
38 * } | |
39 * | |
40 * However, if you want to add the violations to the current context, use the | |
41 * {@link ValidatorInterface::inContext()} method: | |
42 * | |
43 * public function validate($value, Constraint $constraint) | |
44 * { | |
45 * $validator = $this->context->getValidator(); | |
46 * | |
47 * // The violations are added to $this->context | |
48 * $validator | |
49 * ->inContext($this->context) | |
50 * ->validate($value) | |
51 * ; | |
52 * } | |
53 * | |
54 * Additionally, the context provides information about the current state of | |
55 * the validator, such as the currently validated class, the name of the | |
56 * currently validated property and more. These values change over time, so you | |
57 * cannot store a context and expect that the methods still return the same | |
58 * results later on. | |
59 * | |
60 * @author Bernhard Schussek <bschussek@gmail.com> | |
61 */ | |
62 interface ExecutionContextInterface | |
63 { | |
64 /** | |
65 * Adds a violation at the current node of the validation graph. | |
66 * | |
67 * @param string $message The error message | |
68 * @param array $params The parameters substituted in the error message | |
69 */ | |
70 public function addViolation($message, array $params = array()); | |
71 | |
72 /** | |
73 * Returns a builder for adding a violation with extended information. | |
74 * | |
75 * Call {@link ConstraintViolationBuilderInterface::addViolation()} to | |
76 * add the violation when you're done with the configuration: | |
77 * | |
78 * $context->buildViolation('Please enter a number between %min% and %max%.') | |
79 * ->setParameter('%min%', 3) | |
80 * ->setParameter('%max%', 10) | |
81 * ->setTranslationDomain('number_validation') | |
82 * ->addViolation(); | |
83 * | |
84 * @param string $message The error message | |
85 * @param array $parameters The parameters substituted in the error message | |
86 * | |
87 * @return ConstraintViolationBuilderInterface The violation builder | |
88 */ | |
89 public function buildViolation($message, array $parameters = array()); | |
90 | |
91 /** | |
92 * Returns the validator. | |
93 * | |
94 * Useful if you want to validate additional constraints: | |
95 * | |
96 * public function validate($value, Constraint $constraint) | |
97 * { | |
98 * $validator = $this->context->getValidator(); | |
99 * | |
100 * $violations = $validator->validateValue($value, new Length(array('min' => 3))); | |
101 * | |
102 * if (count($violations) > 0) { | |
103 * // ... | |
104 * } | |
105 * } | |
106 * | |
107 * @return ValidatorInterface | |
108 */ | |
109 public function getValidator(); | |
110 | |
111 /** | |
112 * Returns the currently validated object. | |
113 * | |
114 * If the validator is currently validating a class constraint, the | |
115 * object of that class is returned. If it is a validating a property or | |
116 * getter constraint, the object that the property/getter belongs to is | |
117 * returned. | |
118 * | |
119 * In other cases, null is returned. | |
120 * | |
121 * @return object|null The currently validated object or null | |
122 */ | |
123 public function getObject(); | |
124 | |
125 /** | |
126 * Sets the currently validated value. | |
127 * | |
128 * @param mixed $value The validated value | |
129 * @param object|null $object The currently validated object | |
130 * @param MetadataInterface|null $metadata The validation metadata | |
131 * @param string $propertyPath The property path to the current value | |
132 * | |
133 * @internal Used by the validator engine. Should not be called by user | |
134 * code. | |
135 */ | |
136 public function setNode($value, $object, MetadataInterface $metadata = null, $propertyPath); | |
137 | |
138 /** | |
139 * Sets the currently validated group. | |
140 * | |
141 * @param string|null $group The validated group | |
142 * | |
143 * @internal Used by the validator engine. Should not be called by user | |
144 * code. | |
145 */ | |
146 public function setGroup($group); | |
147 | |
148 /** | |
149 * Sets the currently validated constraint. | |
150 * | |
151 * @param Constraint $constraint The validated constraint | |
152 * | |
153 * @internal Used by the validator engine. Should not be called by user | |
154 * code. | |
155 */ | |
156 public function setConstraint(Constraint $constraint); | |
157 | |
158 /** | |
159 * Marks an object as validated in a specific validation group. | |
160 * | |
161 * @param string $cacheKey The hash of the object | |
162 * @param string $groupHash The group's name or hash, if it is group | |
163 * sequence | |
164 * | |
165 * @internal Used by the validator engine. Should not be called by user | |
166 * code. | |
167 */ | |
168 public function markGroupAsValidated($cacheKey, $groupHash); | |
169 | |
170 /** | |
171 * Returns whether an object was validated in a specific validation group. | |
172 * | |
173 * @param string $cacheKey The hash of the object | |
174 * @param string $groupHash The group's name or hash, if it is group | |
175 * sequence | |
176 * | |
177 * @return bool Whether the object was already validated for that | |
178 * group | |
179 * | |
180 * @internal Used by the validator engine. Should not be called by user | |
181 * code. | |
182 */ | |
183 public function isGroupValidated($cacheKey, $groupHash); | |
184 | |
185 /** | |
186 * Marks a constraint as validated for an object. | |
187 * | |
188 * @param string $cacheKey The hash of the object | |
189 * @param string $constraintHash The hash of the constraint | |
190 * | |
191 * @internal Used by the validator engine. Should not be called by user | |
192 * code. | |
193 */ | |
194 public function markConstraintAsValidated($cacheKey, $constraintHash); | |
195 | |
196 /** | |
197 * Returns whether a constraint was validated for an object. | |
198 * | |
199 * @param string $cacheKey The hash of the object | |
200 * @param string $constraintHash The hash of the constraint | |
201 * | |
202 * @return bool Whether the constraint was already validated | |
203 * | |
204 * @internal Used by the validator engine. Should not be called by user | |
205 * code. | |
206 */ | |
207 public function isConstraintValidated($cacheKey, $constraintHash); | |
208 | |
209 /** | |
210 * Marks that an object was initialized. | |
211 * | |
212 * @param string $cacheKey The hash of the object | |
213 * | |
214 * @internal Used by the validator engine. Should not be called by user | |
215 * code. | |
216 * | |
217 * @see ObjectInitializerInterface | |
218 */ | |
219 public function markObjectAsInitialized($cacheKey); | |
220 | |
221 /** | |
222 * Returns whether an object was initialized. | |
223 * | |
224 * @param string $cacheKey The hash of the object | |
225 * | |
226 * @return bool Whether the object was already initialized | |
227 * | |
228 * @internal Used by the validator engine. Should not be called by user | |
229 * code. | |
230 * | |
231 * @see ObjectInitializerInterface | |
232 */ | |
233 public function isObjectInitialized($cacheKey); | |
234 | |
235 /** | |
236 * Returns the violations generated by the validator so far. | |
237 * | |
238 * @return ConstraintViolationListInterface The constraint violation list | |
239 */ | |
240 public function getViolations(); | |
241 | |
242 /** | |
243 * Returns the value at which validation was started in the object graph. | |
244 * | |
245 * The validator, when given an object, traverses the properties and | |
246 * related objects and their properties. The root of the validation is the | |
247 * object from which the traversal started. | |
248 * | |
249 * The current value is returned by {@link getValue}. | |
250 * | |
251 * @return mixed The root value of the validation | |
252 */ | |
253 public function getRoot(); | |
254 | |
255 /** | |
256 * Returns the value that the validator is currently validating. | |
257 * | |
258 * If you want to retrieve the object that was originally passed to the | |
259 * validator, use {@link getRoot}. | |
260 * | |
261 * @return mixed The currently validated value | |
262 */ | |
263 public function getValue(); | |
264 | |
265 /** | |
266 * Returns the metadata for the currently validated value. | |
267 * | |
268 * With the core implementation, this method returns a | |
269 * {@link Mapping\ClassMetadataInterface} instance if the current value is an object, | |
270 * a {@link Mapping\PropertyMetadata} instance if the current value is | |
271 * the value of a property and a {@link Mapping\GetterMetadata} instance if | |
272 * the validated value is the result of a getter method. | |
273 * | |
274 * If the validated value is neither of these, for example if the validator | |
275 * has been called with a plain value and constraint, this method returns | |
276 * null. | |
277 * | |
278 * @return MetadataInterface|null The metadata of the currently validated | |
279 * value. | |
280 */ | |
281 public function getMetadata(); | |
282 | |
283 /** | |
284 * Returns the validation group that is currently being validated. | |
285 * | |
286 * @return string The current validation group | |
287 */ | |
288 public function getGroup(); | |
289 | |
290 /** | |
291 * Returns the class name of the current node. | |
292 * | |
293 * If the metadata of the current node does not implement | |
294 * {@link Mapping\ClassMetadataInterface} or if no metadata is available for the | |
295 * current node, this method returns null. | |
296 * | |
297 * @return string|null The class name or null, if no class name could be found | |
298 */ | |
299 public function getClassName(); | |
300 | |
301 /** | |
302 * Returns the property name of the current node. | |
303 * | |
304 * If the metadata of the current node does not implement | |
305 * {@link PropertyMetadataInterface} or if no metadata is available for the | |
306 * current node, this method returns null. | |
307 * | |
308 * @return string|null The property name or null, if no property name could be found | |
309 */ | |
310 public function getPropertyName(); | |
311 | |
312 /** | |
313 * Returns the property path to the value that the validator is currently | |
314 * validating. | |
315 * | |
316 * For example, take the following object graph: | |
317 * | |
318 * <pre> | |
319 * (Person)---($address: Address)---($street: string) | |
320 * </pre> | |
321 * | |
322 * When the <tt>Person</tt> instance is passed to the validator, the | |
323 * property path is initially empty. When the <tt>$address</tt> property | |
324 * of that person is validated, the property path is "address". When | |
325 * the <tt>$street</tt> property of the related <tt>Address</tt> instance | |
326 * is validated, the property path is "address.street". | |
327 * | |
328 * Properties of objects are prefixed with a dot in the property path. | |
329 * Indices of arrays or objects implementing the {@link \ArrayAccess} | |
330 * interface are enclosed in brackets. For example, if the property in | |
331 * the previous example is <tt>$addresses</tt> and contains an array | |
332 * of <tt>Address</tt> instance, the property path generated for the | |
333 * <tt>$street</tt> property of one of these addresses is for example | |
334 * "addresses[0].street". | |
335 * | |
336 * @param string $subPath Optional. The suffix appended to the current | |
337 * property path. | |
338 * | |
339 * @return string The current property path. The result may be an empty | |
340 * string if the validator is currently validating the | |
341 * root value of the validation graph. | |
342 */ | |
343 public function getPropertyPath($subPath = ''); | |
344 } |