Skip to content

Commit 9c4adba

Browse files
committed
bug #54487 [Validator] Accept Stringable in ExecutionContext::build/addViolation() (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [Validator] Accept `Stringable` in `ExecutionContext::build/addViolation()` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony/symfony-docs#19704 | License | MIT `ConstraintViolationBuilder` accepts any stringable. We mentioned this [in the doc](https://symfony.com/doc/6.4/validation/translations.html) but it doesn't work as explained in the issue. I think `buildViolation()` could accept stringable, also given that `ExecutionContextInterface` defines the type as `string|Stringable` in the PHPDoc. Same for `addViolation()`. Commits ------- 394b514 [Validator] Accept `Stringable` in `ExecutionContext::build/addViolation()`
2 parents 8cf4923 + 394b514 commit 9c4adba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function setConstraint(Constraint $constraint): void
139139
$this->constraint = $constraint;
140140
}
141141

142-
public function addViolation(string $message, array $parameters = []): void
142+
public function addViolation(string|\Stringable $message, array $parameters = []): void
143143
{
144144
$this->violations->add(new ConstraintViolation(
145145
$this->translator->trans($message, $parameters, $this->translationDomain),
@@ -154,7 +154,7 @@ public function addViolation(string $message, array $parameters = []): void
154154
));
155155
}
156156

157-
public function buildViolation(string $message, array $parameters = []): ConstraintViolationBuilderInterface
157+
public function buildViolation(string|\Stringable $message, array $parameters = []): ConstraintViolationBuilderInterface
158158
{
159159
return new ConstraintViolationBuilder(
160160
$this->violations,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy