Way to add error with custom value path
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 167
- Forks
- 47
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 3
Description
In rule handlers Result::addError() is added error message to current key and value path define path into key. Need ability to add error with globally path.
Example:
$result = (new Validator())->validate(
data: ['a' => 1, 'b' => 2],
rules: [
'a' => new Callback(function(){
$result = new Result();
$result->addError('message', valuePath: ['b']);
return $result;
})
],
);
// Errors:
// ['a.b' => ['message']]
Need additional ability add error to key b. May be implement it via adding method addError() to validation context object.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading Result::addError and the rule-handler validation flow described in the issue, then inspect how value paths are combined. Compare the proposed validation-context approach with the existing API. Done means an error created while validating a can target b directly, producing the requested global path rather than a.b, with behavior verified by tests for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100