ConstraintViolation
in package
implements
ConstraintViolationInterface
Default implementation of {@ConstraintViolationInterface}.
Tags
Interfaces, Classes, Traits and Enums
- ConstraintViolationInterface
- A violation of a constraint that happened during validation.
Table of Contents
- $cause : mixed
- $code : mixed
- $constraint : mixed
- $invalidValue : mixed
- $message : mixed
- $messageTemplate : mixed
- $parameters : mixed
- $plural : mixed
- $propertyPath : mixed
- $root : mixed
- __construct() : mixed
- Creates a new constraint violation.
- __toString() : string
- Converts the violation into a string for debugging purposes.
- getCause() : mixed
- Returns the cause of the violation.
- getCode() : string|null
- Returns a machine-digestible error code for the violation.
- getConstraint() : Constraint|null
- Returns the constraint whose validation caused the violation.
- getInvalidValue() : mixed
- Returns the value that caused the violation.
- getMessage() : string|Stringable
- Returns the violation message.
- getMessageTemplate() : string
- Returns the raw violation message.
- getParameters() : array<string|int, mixed>
- Returns the parameters to be inserted into the raw violation message.
- getPlural() : int|null
- Returns a number for pluralizing the violation message.
- getPropertyPath() : string
- Returns the property path from the root element to the violation.
- getRoot() : mixed
- Returns the root element of the validation.
Properties
$cause
private
mixed
$cause
$code
private
mixed
$code
$constraint
private
mixed
$constraint
$invalidValue
private
mixed
$invalidValue
$message
private
mixed
$message
$messageTemplate
private
mixed
$messageTemplate
$parameters
private
mixed
$parameters
$plural
private
mixed
$plural
$propertyPath
private
mixed
$propertyPath
$root
private
mixed
$root
Methods
__construct()
Creates a new constraint violation.
public
__construct(string|Stringable $message, string|null $messageTemplate, array<string|int, mixed> $parameters, mixed $root, string|null $propertyPath, mixed $invalidValue[, int|null $plural = null ][, string|null $code = null ][, Constraint|null $constraint = null ][, mixed $cause = null ]) : mixed
Parameters
- $message : string|Stringable
-
The violation message as a string or a stringable object
- $messageTemplate : string|null
-
The raw violation message
- $parameters : array<string|int, mixed>
-
The parameters to substitute in the raw violation message
- $root : mixed
-
The value originally passed to the validator
- $propertyPath : string|null
-
The property path from the root value to the invalid value
- $invalidValue : mixed
-
The invalid value that caused this violation
- $plural : int|null = null
-
The number for determining the plural form when translating the message
- $code : string|null = null
-
The error code of the violation
- $constraint : Constraint|null = null
-
The constraint whose validation caused the violation
- $cause : mixed = null
-
The cause of the violation
Return values
mixed —__toString()
Converts the violation into a string for debugging purposes.
public
__toString() : string
Return values
string —The violation as string
getCause()
Returns the cause of the violation.
public
getCause() : mixed
Return values
mixed —getCode()
Returns a machine-digestible error code for the violation.
public
getCode() : string|null
Return values
string|null —The error code
getConstraint()
Returns the constraint whose validation caused the violation.
public
getConstraint() : Constraint|null
Return values
Constraint|null —The constraint or null if it is not known
getInvalidValue()
Returns the value that caused the violation.
public
getInvalidValue() : mixed
Return values
mixed —the invalid value that caused the validated constraint to fail
getMessage()
Returns the violation message.
public
getMessage() : string|Stringable
Return values
string|Stringable —The violation message as a string or a stringable object
getMessageTemplate()
Returns the raw violation message.
public
getMessageTemplate() : string
Return values
string —The raw violation message
getParameters()
Returns the parameters to be inserted into the raw violation message.
public
getParameters() : array<string|int, mixed>
Return values
array<string|int, mixed> —a possibly empty list of parameters indexed by the names that appear in the message template
getPlural()
Returns a number for pluralizing the violation message.
public
getPlural() : int|null
Return values
int|null —The number to use to pluralize of the message
getPropertyPath()
Returns the property path from the root element to the violation.
public
getPropertyPath() : string
Return values
string —The property path indicates how the validator reached the invalid value from the root element. If the root element is a Person instance with a property "address" that contains an Address instance with an invalid property "street", the generated property path is "address.street". Property access is denoted by dots, while array access is denoted by square brackets, for example "addresses[1].street".
getRoot()
Returns the root element of the validation.
public
getRoot() : mixed
Return values
mixed —The value that was passed originally to the validator when the validation was started. Because the validator traverses the object graph, the value at which the violation occurs is not necessarily the value that was originally validated.