We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7.2
Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface::setParameter has the following signature:
Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface::setParameter
<?php public function setParameter(string $key, string $value): static;
$value is restricted to a string. However, at least when using ICU message format, objects can be set as a parameter's value: https://symfony.com/doc/current/reference/formats/message_format.html#date-and-time
$value
string
This issue can be worked around by using setParameters(), which doesn't restrict the type
setParameters()
Define a custom validation message in the validators domain (using ICU format):
validators
test_message: "{name} is invalid on {date, date}"
Add a custom assertion to a dummy class (a callback works):
<?php namespace App\Model; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; class Dummy { #[Assert\Callback] public function assertTestFails(ExecutionContextInterface $context) { $context->buildViolation('test_message') ->setParameter('name', 'Test') ->setParameter('date', new \DateTimeImmutable()) ->addViolation() ; } #[Assert\Callback] public function assertTestWorks(ExecutionContextInterface $context) { $context->buildViolation('test_message') ->setParameters([ 'name' => 'Test', 'date' => new \DateTimeImmutable(), ]) ->addViolation() ; } }
Then use Validator component to validate an instance of this class.
Since Translation component does not restrict parameters type, $value should be typed as mixed
No response
The text was updated successfully, but these errors were encountered:
Hey, thanks for your report! There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?
Sorry, something went wrong.
Still relevant
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
7.2
Description
Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface::setParameter
has the following signature:$value
is restricted to astring
. However, at least when using ICU message format, objects can be set as a parameter's value: https://symfony.com/doc/current/reference/formats/message_format.html#date-and-timeThis issue can be worked around by using
setParameters()
, which doesn't restrict the typeHow to reproduce
Define a custom validation message in the
validators
domain (using ICU format):Add a custom assertion to a dummy class (a callback works):
Then use Validator component to validate an instance of this class.
Possible Solution
Since Translation component does not restrict parameters type,
$value
should be typed as mixedAdditional Context
No response
The text was updated successfully, but these errors were encountered: