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