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