Extended validators to allow array values, dependent field validations and added new rules#22
Extended validators to allow array values, dependent field validations and added new rules#22xanish wants to merge 21 commits intohoshomoh:masterfrom
Conversation
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
|
Hi, @hoshomoh, can you help me with this. Checks still haven't completed it seems. |
|
This is quite the change. I will take some time this coming weekend to review. Great initiative. |
…work for both strings and numbers.
… numbers since it doesnt work as expected, would require dependence on all available rules and value type.
|
Made a few changes recently
|
| * parsed in the same order and format as allowedParameters(). | ||
| * This will aid in mapping our parameters to their placeholders. | ||
| */ | ||
| public function parseParameterValues(array $parameters): array; |
There was a problem hiding this comment.
I think this is only useful when there a single parameter is allowed. Instead of doing this, I would rather update
CSVUtils/src/Helpers/FormatsMessages.php
Line 101 in 34afb02
protected function replaceParameterPlaceholder(
string $message,
array $allowedParameters,
array $parameters
): string {
$hasMultipleAllowedParameter = count($allowedParameters) > 1;
$search = $hasMultipleAllowedParameter ? $allowedParameters : $allowedParameters[0];
$replace = $hasMultipleAllowedParameter ? $parameters : implode(',', $parameters);
return str_replace($search, $replace, $message);
}
There was a problem hiding this comment.
Yes, this works as well. I just wanted to keep it open in case someone needed multiple parameters.
| ); | ||
| } | ||
|
|
||
| if ($rule instanceof ArrayParameterizedRuleInterface) { |
| * parsed in the same order and format as allowedParameters(). | ||
| * This will aid in mapping our parameters to their placeholders. | ||
| */ | ||
| public function parseParameterValues(array $parameters): array |
| * parsed in the same order and format as allowedParameters(). | ||
| * This will aid in mapping our parameters to their placeholders. | ||
| */ | ||
| public function parseParameterValues(array $parameters): array |
There was a problem hiding this comment.
I am not sure why this was needed at all. Maybe I am not seeing something. My guess is this will be used like ["requiredIf:field,value"]
There was a problem hiding this comment.
Yes, for my use case I had a couple of fields which had to be made required in case some target column had one of the values specified in :other_values.
There was a problem hiding this comment.
I see. It seems we can't run away from supporting array parameters. Let's do the then. I will make a fix to support array parameters like so, all rules can accept parameters in one of the following ways
["requiredIf:field,value"]["requiredIf" => ["field" => "value"]["requiredIf" => ["field1" => "value1", "field2" => "value2"]["requiredIf" => ["field1" => ["value1", "value2"]]
What do you think? I will try to push this over the weekend.
| return $parameterCount === $ruleParameterCount; | ||
| } | ||
|
|
||
| if ($rule instanceof ArrayParameterizedRuleInterface) { |
Hi,
I am planning to use the library on one of my projects. Thought I'd share some changes here as well to help out the community.
inandrequired_ifusing the above interfacepasses()function now receives the current validation row which allows for dependent field validation checksrequired_ifwhich is based on dependent field validationrequiredrule, we can easily ignore empty cells unless required by user explicitlyalpha,alpha_num,in,integer,numericandurlwill now return true for null / empty string valuesLet me know if any change is required.