7499d890ff6b018d14952a9b85bf1da592c32403
[yaffs-website] / vendor / symfony / validator / ConstraintViolationInterface.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;
13
14 /**
15  * A violation of a constraint that happened during validation.
16  *
17  * For each constraint that fails during validation one or more violations are
18  * created. The violations store the violation message, the path to the failing
19  * element in the validation graph and the root element that was originally
20  * passed to the validator. For example, take the following graph:
21  *
22  * <pre>
23  * (Person)---(firstName: string)
24  *      \
25  *   (address: Address)---(street: string)
26  * </pre>
27  *
28  * If the <tt>Person</tt> object is validated and validation fails for the
29  * "firstName" property, the generated violation has the <tt>Person</tt>
30  * instance as root and the property path "firstName". If validation fails
31  * for the "street" property of the related <tt>Address</tt> instance, the root
32  * element is still the person, but the property path is "address.street".
33  *
34  * @author Bernhard Schussek <bschussek@gmail.com>
35  */
36 interface ConstraintViolationInterface
37 {
38     /**
39      * Returns the violation message.
40      *
41      * @return string The violation message
42      */
43     public function getMessage();
44
45     /**
46      * Returns the raw violation message.
47      *
48      * The raw violation message contains placeholders for the parameters
49      * returned by {@link getParameters}. Typically you'll pass the
50      * message template and parameters to a translation engine.
51      *
52      * @return string The raw violation message
53      */
54     public function getMessageTemplate();
55
56     /**
57      * Returns the parameters to be inserted into the raw violation message.
58      *
59      * @return array A possibly empty list of parameters indexed by the names
60      *               that appear in the message template.
61      *
62      * @see getMessageTemplate()
63      */
64     public function getParameters();
65
66     /**
67      * Returns a number for pluralizing the violation message.
68      *
69      * For example, the message template could have different translation based
70      * on a parameter "choices":
71      *
72      * <ul>
73      * <li>Please select exactly one entry. (choices=1)</li>
74      * <li>Please select two entries. (choices=2)</li>
75      * </ul>
76      *
77      * This method returns the value of the parameter for choosing the right
78      * pluralization form (in this case "choices").
79      *
80      * @return int|null The number to use to pluralize of the message
81      */
82     public function getPlural();
83
84     /**
85      * Returns the root element of the validation.
86      *
87      * @return mixed The value that was passed originally to the validator when
88      *               the validation was started. Because the validator traverses
89      *               the object graph, the value at which the violation occurs
90      *               is not necessarily the value that was originally validated.
91      */
92     public function getRoot();
93
94     /**
95      * Returns the property path from the root element to the violation.
96      *
97      * @return string The property path indicates how the validator reached
98      *                the invalid value from the root element. If the root
99      *                element is a <tt>Person</tt> instance with a property
100      *                "address" that contains an <tt>Address</tt> instance
101      *                with an invalid property "street", the generated property
102      *                path is "address.street". Property access is denoted by
103      *                dots, while array access is denoted by square brackets,
104      *                for example "addresses[1].street".
105      */
106     public function getPropertyPath();
107
108     /**
109      * Returns the value that caused the violation.
110      *
111      * @return mixed The invalid value that caused the validated constraint to
112      *               fail.
113      */
114     public function getInvalidValue();
115
116     /**
117      * Returns a machine-digestible error code for the violation.
118      *
119      * @return string|null The error code
120      */
121     public function getCode();
122 }