somnambulist-tech / validation

A re-write of rakit/validation, a standalone validation library inspired by Laravel Validation
MIT License
44 stars 13 forks source link

support customize dot flag of array keys #31

Closed messikiller closed 3 weeks ago

messikiller commented 1 month ago

In some cases, keys of inputs array has already contain the default dot flag '.', it maybe make user confused while match multiple dimension keys. such as the inputs array:

$data = [
    'foo.bar' => [
        'baz' => 'jax'
    ]
];

so. i append setDotKey() and getDotKey() for the class validation,it is possible if user want to specify another delimiter:

$validation = (new Factory)->make($inputs, $rules);
$validation->setDotKey('/');
dave-redfern commented 3 weeks ago

@messikiller Thank you for your PR and my apologies for taking this long to respond.

At this time I am not going to accept your PR. This change represents a fundamental alteration at a low level, that does not have sufficient testing to ensure it works across all aspects of the library. You would need to write tests for every rule and multiple scenarios to ensure compatibility in all contexts.

If you require this functionality, for now, it would be better if you pre-processed the data to be validated and replace dotted keys with another character. Then they can be changed back after validation if needed.

I may consider a change like this in the next major version of the validation library, but for now it is too risky to integrate.