Replies: 2 comments · 8 replies
-
|
I don't know how you construct the |
Beta Was this translation helpful? Give feedback.
-
|
I would check two separate things here. First, the common gotcha: make sure the PHP The shape should be: #[\Attribute]
final class MyConstraint extends Constraint
{
}and: final class MyConstraintValidator extends ConstraintValidator
{
public function __construct(private SomeService $service) {}
public function validate(mixed $value, Constraint $constraint): void
{
// use $this->service here
}
}Second, the validator factory in your test/app must come from the container. In a full Symfony app, So the rule of thumb is:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Symfony version(s) affected
5.4
Description
Inject a dependency in a custom validator results in a dependency injection error.
How to reproduce
services.yamlPossible Solution
No response
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions