-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] support \Stringable
instances in all constraints
#53374
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
Conversation
xabbuh
commented
Jan 3, 2024
Q | A |
---|---|
Branch? | 7.1 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Issues | |
License | MIT |
f118c4f
to
68e0cc3
Compare
\Stringable
instances in all constraints
68e0cc3
to
04bdd6c
Compare
@@ -36,7 +36,7 @@ public function validate(#[\SensitiveParameter] mixed $value, Constraint $constr | |||
return; | |||
} | |||
|
|||
if (!\is_string($value)) { | |||
if (!\is_string($value) && !$value instanceof \Stringable) { | |||
throw new UnexpectedValueException($value, 'string'); | |||
} | |||
$passwordStrengthEstimator = $this->passwordStrengthEstimator ?? self::estimateStrength(...); |
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.
The value may be casted to (string)
when calling $passwordStrengthEstimator($value)
. We don't know how this is handled by the $passwordStrengthEstimator
callable.
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.
indeed, done
It would be better with tests. |
04bdd6c
to
05f9f45
Compare
@GromNaN tests added |
Thank you @xabbuh. |