Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Validator; Chris@0: Chris@0: /** Chris@0: * A violation of a constraint that happened during validation. Chris@0: * Chris@0: * For each constraint that fails during validation one or more violations are Chris@0: * created. The violations store the violation message, the path to the failing Chris@0: * element in the validation graph and the root element that was originally Chris@0: * passed to the validator. For example, take the following graph: Chris@0: * Chris@17: * (Person)---(firstName: string) Chris@17: * \ Chris@17: * (address: Address)---(street: string) Chris@0: * Chris@0: * If the Person object is validated and validation fails for the Chris@0: * "firstName" property, the generated violation has the Person Chris@0: * instance as root and the property path "firstName". If validation fails Chris@0: * for the "street" property of the related Address instance, the root Chris@0: * element is still the person, but the property path is "address.street". Chris@0: * Chris@0: * @author Bernhard Schussek Chris@0: */ Chris@0: interface ConstraintViolationInterface Chris@0: { Chris@0: /** Chris@0: * Returns the violation message. Chris@0: * Chris@0: * @return string The violation message Chris@0: */ Chris@0: public function getMessage(); Chris@0: Chris@0: /** Chris@0: * Returns the raw violation message. Chris@0: * Chris@0: * The raw violation message contains placeholders for the parameters Chris@0: * returned by {@link getParameters}. Typically you'll pass the Chris@0: * message template and parameters to a translation engine. Chris@0: * Chris@0: * @return string The raw violation message Chris@0: */ Chris@0: public function getMessageTemplate(); Chris@0: Chris@0: /** Chris@0: * Returns the parameters to be inserted into the raw violation message. Chris@0: * Chris@14: * @return array a possibly empty list of parameters indexed by the names Chris@14: * that appear in the message template Chris@0: * Chris@0: * @see getMessageTemplate() Chris@0: */ Chris@0: public function getParameters(); Chris@0: Chris@0: /** Chris@0: * Returns a number for pluralizing the violation message. Chris@0: * Chris@0: * For example, the message template could have different translation based Chris@0: * on a parameter "choices": Chris@0: * Chris@0: * Chris@0: * Chris@0: * This method returns the value of the parameter for choosing the right Chris@0: * pluralization form (in this case "choices"). Chris@0: * Chris@0: * @return int|null The number to use to pluralize of the message Chris@0: */ Chris@0: public function getPlural(); Chris@0: Chris@0: /** Chris@0: * Returns the root element of the validation. Chris@0: * Chris@0: * @return mixed The value that was passed originally to the validator when Chris@0: * the validation was started. Because the validator traverses Chris@0: * the object graph, the value at which the violation occurs Chris@0: * is not necessarily the value that was originally validated. Chris@0: */ Chris@0: public function getRoot(); Chris@0: Chris@0: /** Chris@0: * Returns the property path from the root element to the violation. Chris@0: * Chris@0: * @return string The property path indicates how the validator reached Chris@0: * the invalid value from the root element. If the root Chris@0: * element is a Person instance with a property Chris@0: * "address" that contains an Address instance Chris@0: * with an invalid property "street", the generated property Chris@0: * path is "address.street". Property access is denoted by Chris@0: * dots, while array access is denoted by square brackets, Chris@0: * for example "addresses[1].street". Chris@0: */ Chris@0: public function getPropertyPath(); Chris@0: Chris@0: /** Chris@0: * Returns the value that caused the violation. Chris@0: * Chris@14: * @return mixed the invalid value that caused the validated constraint to Chris@14: * fail Chris@0: */ Chris@0: public function getInvalidValue(); Chris@0: Chris@0: /** Chris@0: * Returns a machine-digestible error code for the violation. Chris@0: * Chris@0: * @return string|null The error code Chris@0: */ Chris@0: public function getCode(); Chris@0: }