Array validation with non iterative rules #753
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ok, one more PR related to Validator and its ability to validate arrays.
How it works.
We have several additional methods in Factory and Validator:
Factory:
Validator:
These methods allow user to set/remove/view so called
nonIterative
rules. If currently validated rule is set innonIterative
array, then current value will be validated as a whole array (as it is), otherwise it'll be validated item by item if that value is an array but not present innonIterative
.With default settings, Validator will work the same way as described in #255 PR.
Except of several cases:
exists
rule will use "WHERE IN", so if value is an array there won't be tons of queriessame
&different
will compare whole array withother
attributeDefault
nonIterative
:array('Exists', 'Same', 'Different')
.Add/Remove rules
Global:
Local:
You can explicitly remove any rule from Factory and Validator:
In order to check which rules are set you can call
getNonIterative
(both on Factory and Validator class).Custom rules
If user creates custom validation rule via extends or just extends Validator class, then this rule will be validated on
per item
basis. You'll have to explicitly add your custom rule to the nonIterative array viaaddNonIterative
on Factory or Validator class.