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