ConstraintViolation
in package
implements
ConstraintViolationInterface
Default implementation of {@ConstraintViolationInterface}.
Tags
Table of Contents
Interfaces
- ConstraintViolationInterface
- A violation of a constraint that happened during validation.
Properties
- $cause : mixed
- $code : string|null
- $constraint : mixed
- $invalidValue : mixed
- $message : string|Stringable
- $messageTemplate : string|null
- $parameters : array<string|int, mixed>
- $plural : int|null
- $propertyPath : string|null
- $root : mixed
Methods
- __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
string|null
$code
$constraint
private
mixed
$constraint
$invalidValue
private
mixed
$invalidValue
$message
private
string|Stringable
$message
$messageTemplate
private
string|null
$messageTemplate
$parameters
private
array<string|int, mixed>
$parameters
$plural
private
int|null
$plural
$propertyPath
private
string|null
$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
__toString()
Converts the violation into a string for debugging purposes.
public
__toString() : string
Return values
stringgetCause()
Returns the cause of the violation.
public
getCause() : mixed
getCode()
Returns a machine-digestible error code for the violation.
public
getCode() : string|null
Return values
string|nullgetConstraint()
Returns the constraint whose validation caused the violation.
public
getConstraint() : Constraint|null
Return values
Constraint|nullgetInvalidValue()
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|StringablegetMessageTemplate()
Returns the raw violation message.
public
getMessageTemplate() : string
Return values
stringgetParameters()
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|nullgetPropertyPath()
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.