public function ExecutionContext::addViolation in Plug 7
Same name in this branch
- 7 lib/Symfony/validator/Symfony/Component/Validator/ExecutionContext.php \Symfony\Component\Validator\ExecutionContext::addViolation()
- 7 lib/Symfony/validator/Symfony/Component/Validator/Context/ExecutionContext.php \Symfony\Component\Validator\Context\ExecutionContext::addViolation()
Adds a violation at the current node of the validation graph.
Note: the parameters $invalidValue, $plural and $code are deprecated since version 2.5 and will be removed in 3.0.
@api
Parameters
string $message The error message:
array $params The parameters substituted in the error message:
mixed $invalidValue The invalid, validated value:
int|null $plural The number to use to pluralize of the message:
int|null $code The violation code:
Overrides ExecutionContextInterface::addViolation
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ ExecutionContext.php, line 93
Class
- ExecutionContext
- Default implementation of {@link ExecutionContextInterface}.
Namespace
Symfony\Component\ValidatorCode
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null) {
if (null === $plural) {
$translatedMessage = $this->translator
->trans($message, $params, $this->translationDomain);
}
else {
try {
$translatedMessage = $this->translator
->transChoice($message, $plural, $params, $this->translationDomain);
} catch (\InvalidArgumentException $e) {
$translatedMessage = $this->translator
->trans($message, $params, $this->translationDomain);
}
}
$this->globalContext
->getViolations()
->add(new ConstraintViolation($translatedMessage, $message, $params, $this->globalContext
->getRoot(), $this->propertyPath, func_num_args() >= 3 ? $invalidValue : $this->value, $plural, $code));
}