-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
ConstraintValidator and ConstraintValidatorInterface use deprecated entity #11049
New issue
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
Comments
@webmozart any idea how to solve this ? |
@stof @webmozart Any update on this yet? |
@tobias-93 The solution is to (a) configure your project to use the 2.5 API and (b) simply use the methods of the new interface. In order to circumvent IDE errors, you can add: use Symfony\Component\Validator\Context\ExecutionContextInterface;
class MyValidator extends ConstraintValidator
{
/**
* @var ExecutionContextInterface
*/
protected $context;
// ...
} to your constraint validator (or your project's base validator). Be aware that if you use the new methods, your code cannot be used with the <2.5 API anymore (obviously). So my recommendation is:
|
@webmozart are all core constraint validators written in a way support all APIs (i.e 2.4, 2.5-bc and 2.5) ? Or do they require enabling at least the legacy mode ? |
@stof Currently, both the 2.5-bc and 2.5 APIs use the class However, I guess it would be wise to change this to use
|
@webmozart Thank you for your comments, I will adapt my project using your guideline. |
…ebmozart) This PR was squashed before being merged into the 2.5 branch (closes #11485). Discussion ---------- [Validator] Constraint validators now use the 2.5 API | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See the comments in #11049 for the origin of this PR. Currently, the 2.5 API needs to use `LegacyExecutionContextFactory` because the constraint validators rely on methods from the old `ExecutionContext` class (like `validate()`, `validateValue()`). Consequently it is impossible to switch to the pure 2.5 API and check whether all calls to deprecated methods were removed from application code. This is fixed now. This PR also introduces a complete test suite to test each constraint validator against all three APIs: 2.4, 2.5-BC and 2.5. Currently, some tests are not executed yet when running the complete test suite is run. I expect this to be fixed soon (ticket: sebastianbergmann/phpunit#529, pr: sebastianbergmann/phpunit#1327). Commits ------- 295e5bb [Validator] Fixed failing tests 3bd6d80 [Validator] CS fixes 870a41a [FrameworkBundle] Made ConstraintValidatorFactory aware of the legacy validators 7504448 [Validator] Added extensive test coverage for the constraint validators for the different APIs 8e461af [Validator] Constraint validators now use the 2.5 API. For incompatible validators, legacy validators were created
The parameter
$context
ofSymfony\Component\Validator\ConstraintValidator
andConstraintValidatorInterface
is of typeSymfony\Component\Validator\ExecutionContextInterface
, which is deprecated. It would be useful for projects using the Validator api which want to update to the new api, to allow using the new entitySymfony\Component\Validator\Context\ExecutionContextInterface
, since it adds the replacementbuildViolation
for the deprecatedaddViolationAt
function.Could you add that support please?
Thanks, Tobias
The text was updated successfully, but these errors were encountered: