-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Expression language allow null #41329
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ public function validate($expression, Constraint $constraint): void | |
throw new UnexpectedTypeException($constraint, ExpressionLanguageSyntax::class); | ||
} | ||
|
||
if (true === $constraint->allowNullAndEmptyString && (null === $expression || '' === $expression)) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The deprecation should be triggered here instead of the constraint constructor to ensure runtime context, otherwise it may be lost in the app cache warm up, something like: if (null === $expression || '' === $expression) {
if ($constraint->allowNullAndEmptyString) {
return;
}
trigger_deprecation(...);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll wait for other comments about it, because all triggered deprecations in Constraints are in the Constraint class and not in the Validator (eg: Length, Range) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say that it should never be the case, otherwise it may end up as symfony/symfony-docs#14785 (ref symfony/symfony-docs#14785 (comment)). |
||
} | ||
|
||
if (!\is_string($expression)) { | ||
throw new UnexpectedValueException($expression, 'string'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we move the parameter at the end for BC? (I wonder if it matters for annotations 🤔)