4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator;
15 * A violation of a constraint that happened during validation.
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:
23 * (Person)---(firstName: string)
25 * (address: Address)---(street: string)
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".
34 * @author Bernhard Schussek <bschussek@gmail.com>
36 interface ConstraintViolationInterface
39 * Returns the violation message.
41 * @return string The violation message
43 public function getMessage();
46 * Returns the raw violation message.
48 * The raw violation message contains placeholders for the parameters
49 * returned by {@link getMessageParameters}. Typically you'll pass the
50 * message template and parameters to a translation engine.
52 * @return string The raw violation message
54 public function getMessageTemplate();
57 * Returns the parameters to be inserted into the raw violation message.
59 * @return array A possibly empty list of parameters indexed by the names
60 * that appear in the message template.
62 * @see getMessageTemplate()
63 * @deprecated since version 2.7, to be replaced by getParameters() in 3.0.
65 public function getMessageParameters();
68 * Returns a number for pluralizing the violation message.
70 * For example, the message template could have different translation based
71 * on a parameter "choices":
74 * <li>Please select exactly one entry. (choices=1)</li>
75 * <li>Please select two entries. (choices=2)</li>
78 * This method returns the value of the parameter for choosing the right
79 * pluralization form (in this case "choices").
81 * @return int|null The number to use to pluralize of the message
83 * @deprecated since version 2.7, to be replaced by getPlural() in 3.0.
85 public function getMessagePluralization();
88 * Returns the root element of the validation.
90 * @return mixed The value that was passed originally to the validator when
91 * the validation was started. Because the validator traverses
92 * the object graph, the value at which the violation occurs
93 * is not necessarily the value that was originally validated.
95 public function getRoot();
98 * Returns the property path from the root element to the violation.
100 * @return string The property path indicates how the validator reached
101 * the invalid value from the root element. If the root
102 * element is a <tt>Person</tt> instance with a property
103 * "address" that contains an <tt>Address</tt> instance
104 * with an invalid property "street", the generated property
105 * path is "address.street". Property access is denoted by
106 * dots, while array access is denoted by square brackets,
107 * for example "addresses[1].street".
109 public function getPropertyPath();
112 * Returns the value that caused the violation.
114 * @return mixed The invalid value that caused the validated constraint to
117 public function getInvalidValue();
120 * Returns a machine-digestible error code for the violation.
122 * @return string|null The error code
124 public function getCode();