-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.2] [Validator] "AnyOf" validation constraint #4861
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
BTW I named it |
*/ | ||
class AnyOf extends Constraint | ||
{ | ||
public $message = 'Value "{{ value }}" did not pass validation against any of constraints in the list [{{ constraints }}]'; |
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.
this is wrong. we don't want to display a list of constraint classes to the visitor seing a form error.
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.
I refactored the code to only display all the child violations if validation against AnyOf
failed. The only bad thing here is that there is no message that there had to be ANY of those to match. But merging those messages into AnyOf
's own error message is not a good idea as well.
@stof what do you think about constraint naming? I described the reason I named it so in the first comment but maybe it should be named just |
I think AnyOf is better than Any to avoid confusion with All, as they are indeed totally different. |
Do you accept extending |
Your example with Null or MinLength is bad because MinLength alone also allows null. So in this case AnyOf is not even necessary. |
@Tobion Yes, I know, this is why I wrote that actually it was created to be used together with a more complex constraints. The better example may be with |
BTW, why does In this case |
@olegstepura Using the Doctrine ArrayCollection would introduce a hard dependency to doctrine common in the component. |
@stof Then creating some symfony/common to store such common things makes sense. I'm sure this class is not the only one in the framework that implements all this interfaces, and each class implements it again and agian by itself. There is |
Having a common base class for them does not make sense. They are different concepts. It could be a use case for traits, but Symfony cannot drop the support of PHP 5.3. |
Well, ok, you know better. Any other improvements on this pull request needed to be done? |
Well, the description marks it for 2.2, so it is not the priority (priority is to release beta3) |
@bschussek @fabpot ping |
use Symfony\Component\Validator\ConstraintValidator; | ||
|
||
/** | ||
* AnyValidator class. |
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.
this should be equals name of the class or just removed
This PR was merged into the master branch. Commits ------- a7ce6be Fixed typos Discussion ---------- Fixed typos
This PR was merged into the master branch. Commits ------- 2817a47 [Finder] Fixed filename containing space bug in gnu adapter. 9bf7cb0 [Finder] Added filename containing space to tests. Discussion ---------- [Finder] Fixed filename containing space bug in gnu find adapter. Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes: symfony#5851 `GNU find` adapter now uses `cut` instead of `awk`.
…o any_of_validator Conflicts: src/Symfony/Component/Validator/Constraints/AnyOfValidator.php
@bschussek I'm not sure why you created those functionality, but I did that when I had a need for it. It was not an abstract function. But since it's open already for 5 months and no one can tell if this will ever be merged maybe it'll be closed as well sometimes. |
@olegstepura Yes, let's close this until more people cry for it - then at least we'll be able to have a lively discussion about it. :) |
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Todo: documentation (hopefully not me)
License of the code: MIT
Documentation PR: none
Here is proposal for
AnyOf
validation constraint. It's used to validate against any of given child validation constraints. If any of child validation constraints will pass validation of given value thenAnyOf
will pass as well.This will pass validation without violations if
$secondName
is anull
OR if it's a string with a minimum length of 3.Actually it was created to be used together with a more complex constraints.