yiisoft / yiisoft/validator

Add `CallbackRule` rule

Open
#781 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:under discussion
Dominant language
PHP
Stars
167
Forks
47
Avg merge
1d 19h
Merged PRs (30d)
3

Description

This is analogue of Callback but it returns a different rule that is already being applied.

Example of usage:

/**
 * @var array<int, string>
 */
private readonly array $categories;

#[CallbackRule(method: categoryIdRule)]
public int|null $categoryId = null;

private function categoryIdRule(): RuleInterface
{
    return new In(array_keys($this->categories));
}

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 locating the existing Callback rule and its tests, then compare how the example's CallbackRule method should return a RuleInterface. Done means the new rule supports the shown attribute usage and applies the returned rule, with tests covering the example behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.