-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC][OptionsResolver] Constraints #36820
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
I'm 👎 on this proposal. This would coupling two components unnecessarily IMHO. Instead you can check these constraints in |
the validator is a service, optionsresolver is not. This makes coupling the components a bit harder as well. I suggest to leverage #31466 in userland. |
I'm not sure if we need such constraints in the options resolver, but would it make sense to allow a custom validation callable? This would work nice with the introduction of |
|
I did not counted with
Actually better is to create OptionsResolver, resolve parameters and than create constraints and validate. |
Callable does if I'm correct: $resolver->setAllowedValues('name', Validation::createCallable([
new Assert\Length(['min' => 10 ]),
])); |
@wouterj I don't think it works because |
then converting the validation exception to a bool value out-of-the-box, sounds nice :) |
Thank you for this suggestion. |
@carsonbot alright, here you have some activity: #40240 😉 |
…at returns a boolean instead of exception (wouterj) This PR was merged into the 5.3-dev branch. Discussion ---------- [Validator] Add Validation::createIsValidCallable() that returns a boolean instead of exception | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #36820 | License | MIT | Doc PR | tbd This adds a `Validator::createValidCallable()` (I'm very open for other name suggestions) that returns a boolean instead of exceptions. This allows usingit in places where booleans are expected, for instance in the referenced OptionsResolver case: ```php $resolver->setAllowedValues('name', Validation::createValidCallable( new Assert\Length(['min' => 10 ]) )); ``` Commits ------- e731f5f [Validator] Add createValidCallable() that returns a boolean
Description
OptionConfigurator would have new method
checkConstraints(Constraint[] $constraints)
. User can set validation constraints that will be checked by OptionResolver.Similar like form fields can have constraints.
In OptionsResolver would be new method
addConstraints(string $option, Constraint[] $constraints)
and resolve() would be created Validator a validate all options.Example
The text was updated successfully, but these errors were encountered: