Minor dependency updates
[yaffs-website] / vendor / symfony / validator / Context / ExecutionContextInterface.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\Context;
13
14 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
16 use Symfony\Component\Validator\Mapping\MetadataInterface;
17 use Symfony\Component\Validator\Validator\ValidatorInterface;
18 use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
19
20 /**
21  * The context of a validation run.
22  *
23  * The context collects all violations generated during the validation. By
24  * default, validators execute all validations in a new context:
25  *
26  *     $violations = $validator->validate($object);
27  *
28  * When you make another call to the validator, while the validation is in
29  * progress, the violations will be isolated from each other:
30  *
31  *     public function validate($value, Constraint $constraint)
32  *     {
33  *         $validator = $this->context->getValidator();
34  *
35  *         // The violations are not added to $this->context
36  *         $violations = $validator->validate($value);
37  *     }
38  *
39  * However, if you want to add the violations to the current context, use the
40  * {@link ValidatorInterface::inContext()} method:
41  *
42  *     public function validate($value, Constraint $constraint)
43  *     {
44  *         $validator = $this->context->getValidator();
45  *
46  *         // The violations are added to $this->context
47  *         $validator
48  *             ->inContext($this->context)
49  *             ->validate($value)
50  *         ;
51  *     }
52  *
53  * Additionally, the context provides information about the current state of
54  * the validator, such as the currently validated class, the name of the
55  * currently validated property and more. These values change over time, so you
56  * cannot store a context and expect that the methods still return the same
57  * results later on.
58  *
59  * @author Bernhard Schussek <bschussek@gmail.com>
60  */
61 interface ExecutionContextInterface extends LegacyExecutionContextInterface
62 {
63     /**
64      * Returns a builder for adding a violation with extended information.
65      *
66      * Call {@link ConstraintViolationBuilderInterface::addViolation()} to
67      * add the violation when you're done with the configuration:
68      *
69      *     $context->buildViolation('Please enter a number between %min% and %max%.')
70      *         ->setParameter('%min%', 3)
71      *         ->setParameter('%max%', 10)
72      *         ->setTranslationDomain('number_validation')
73      *         ->addViolation();
74      *
75      * @param string $message    The error message
76      * @param array  $parameters The parameters substituted in the error message
77      *
78      * @return ConstraintViolationBuilderInterface The violation builder
79      */
80     public function buildViolation($message, array $parameters = array());
81
82     /**
83      * Returns the validator.
84      *
85      * Useful if you want to validate additional constraints:
86      *
87      *     public function validate($value, Constraint $constraint)
88      *     {
89      *         $validator = $this->context->getValidator();
90      *
91      *         $violations = $validator->validateValue($value, new Length(array('min' => 3)));
92      *
93      *         if (count($violations) > 0) {
94      *             // ...
95      *         }
96      *     }
97      *
98      * @return ValidatorInterface
99      */
100     public function getValidator();
101
102     /**
103      * Returns the currently validated object.
104      *
105      * If the validator is currently validating a class constraint, the
106      * object of that class is returned. If it is a validating a property or
107      * getter constraint, the object that the property/getter belongs to is
108      * returned.
109      *
110      * In other cases, null is returned.
111      *
112      * @return object|null The currently validated object or null
113      */
114     public function getObject();
115
116     /**
117      * Sets the currently validated value.
118      *
119      * @param mixed                  $value        The validated value
120      * @param object|null            $object       The currently validated object
121      * @param MetadataInterface|null $metadata     The validation metadata
122      * @param string                 $propertyPath The property path to the current value
123      *
124      * @internal Used by the validator engine. Should not be called by user
125      *           code.
126      */
127     public function setNode($value, $object, MetadataInterface $metadata = null, $propertyPath);
128
129     /**
130      * Sets the currently validated group.
131      *
132      * @param string|null $group The validated group
133      *
134      * @internal Used by the validator engine. Should not be called by user
135      *           code.
136      */
137     public function setGroup($group);
138
139     /**
140      * Sets the currently validated constraint.
141      *
142      * @param Constraint $constraint The validated constraint
143      *
144      * @internal Used by the validator engine. Should not be called by user
145      *           code.
146      */
147     public function setConstraint(Constraint $constraint);
148
149     /**
150      * Marks an object as validated in a specific validation group.
151      *
152      * @param string $cacheKey  The hash of the object
153      * @param string $groupHash The group's name or hash, if it is group
154      *                          sequence
155      *
156      * @internal Used by the validator engine. Should not be called by user
157      *           code.
158      */
159     public function markGroupAsValidated($cacheKey, $groupHash);
160
161     /**
162      * Returns whether an object was validated in a specific validation group.
163      *
164      * @param string $cacheKey  The hash of the object
165      * @param string $groupHash The group's name or hash, if it is group
166      *                          sequence
167      *
168      * @return bool Whether the object was already validated for that
169      *              group
170      *
171      * @internal Used by the validator engine. Should not be called by user
172      *           code.
173      */
174     public function isGroupValidated($cacheKey, $groupHash);
175
176     /**
177      * Marks a constraint as validated for an object.
178      *
179      * @param string $cacheKey       The hash of the object
180      * @param string $constraintHash The hash of the constraint
181      *
182      * @internal Used by the validator engine. Should not be called by user
183      *           code.
184      */
185     public function markConstraintAsValidated($cacheKey, $constraintHash);
186
187     /**
188      * Returns whether a constraint was validated for an object.
189      *
190      * @param string $cacheKey       The hash of the object
191      * @param string $constraintHash The hash of the constraint
192      *
193      * @return bool Whether the constraint was already validated
194      *
195      * @internal Used by the validator engine. Should not be called by user
196      *           code.
197      */
198     public function isConstraintValidated($cacheKey, $constraintHash);
199
200     /**
201      * Marks that an object was initialized.
202      *
203      * @param string $cacheKey The hash of the object
204      *
205      * @internal Used by the validator engine. Should not be called by user
206      *           code.
207      *
208      * @see ObjectInitializerInterface
209      */
210     public function markObjectAsInitialized($cacheKey);
211
212     /**
213      * Returns whether an object was initialized.
214      *
215      * @param string $cacheKey The hash of the object
216      *
217      * @return bool Whether the object was already initialized
218      *
219      * @internal Used by the validator engine. Should not be called by user
220      *           code.
221      *
222      * @see ObjectInitializerInterface
223      */
224     public function isObjectInitialized($cacheKey);
225 }