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 getParameters}. 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()
64 public function getParameters();
67 * Returns a number for pluralizing the violation message.
69 * For example, the message template could have different translation based
70 * on a parameter "choices":
73 * <li>Please select exactly one entry. (choices=1)</li>
74 * <li>Please select two entries. (choices=2)</li>
77 * This method returns the value of the parameter for choosing the right
78 * pluralization form (in this case "choices").
80 * @return int|null The number to use to pluralize of the message
82 public function getPlural();
85 * Returns the root element of the validation.
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.
92 public function getRoot();
95 * Returns the property path from the root element to the violation.
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".
106 public function getPropertyPath();
109 * Returns the value that caused the violation.
111 * @return mixed the invalid value that caused the validated constraint to
114 public function getInvalidValue();
117 * Returns a machine-digestible error code for the violation.
119 * @return string|null The error code
121 public function getCode();