Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Validator] Allow creating constraints with required arguments#45072
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
169216f tobc1205dComparesrc/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
bc1205d to16ef147Comparesrc/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
16ef147 tof72c5c0Comparesrc/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
5d6405d to63f4d0cComparenicolas-grekas commentedMar 28, 2022
If I'm not wrong, it's already possible to write constraints with required args, but then they can only be loaded via annotations, and not via yaml/xml, isn't it? Relying on |
norkunas commentedMar 29, 2022
yes
And what that |
nicolas-grekas commentedMar 29, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Exactly that: a marker to express that some constraints opt-in to get their arguments by a named constructor.
The next logical step would be to allow constructing constraints using named arguments, even if no arguments are required. |
norkunas commentedMar 29, 2022
Maybe then an attribute could be used for this? because if I'd extend an existing constraint it wouldn't work |
nicolas-grekas commentedMar 29, 2022
That'd work for me also! |
63f4d0c to44c1c1dComparenorkunas commentedMar 29, 2022
Thank you, updated. |
44c1c1d to5aec890Compare
nicolas-grekas left a comment
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.
almost good to me, I just have some questions
src/Symfony/Component/Validator/Tests/Fixtures/ConstraintWithRequiredArgument.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
5aec890 tof22433fComparefabpot commentedApr 1, 2022
Thank you@norkunas. |
Uh oh!
There was an error while loading.Please reload this page.
Before PHP8 validation constraint usage was only possible with providing options as an array, but now with native PHP attributes we can provide as named arguments. And to require some arguments overriding
getRequiredOptionsmethod in Constraint was necessary to get proper validation. But since PHP8.1 we can just make arguments required in the Attribute constructor and try to unpack them because it is possible now.