Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Jan 3, 2024

Q A
Branch? 7.1
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

@OskarStark OskarStark changed the title [Validator] support Stringable instances in all constraints [Validator] support \Stringable instances in all constraints Jan 3, 2024
@xabbuh xabbuh force-pushed the constraint-stringable-value branch from 68e0cc3 to 04bdd6c Compare January 3, 2024 12:19
@@ -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(...);
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, done

@GromNaN
Copy link
Member

GromNaN commented Jan 3, 2024

It would be better with tests.

@xabbuh xabbuh force-pushed the constraint-stringable-value branch from 04bdd6c to 05f9f45 Compare January 3, 2024 14:28
@xabbuh
Copy link
Member Author

xabbuh commented Jan 3, 2024

@GromNaN tests added

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit 4266345 into symfony:7.1 Jan 4, 2024
@xabbuh xabbuh deleted the constraint-stringable-value branch January 4, 2024 07:35
@fabpot fabpot mentioned this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants