yiisoft / yiisoft/validator

Way to add error with custom value path

Open
#651 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:ready for adoption type:enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.