yiisoft / yiisoft/validator

Allow to apply the same validating ruleset to multiple attributes

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

Nobody has claimed this yet.

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

Description

What steps will reproduce the problem?

It is impossible to apply the same set of rules to multiple attributes of an object or an array.

What is the expected result?

Would be really useful to be able to apply same set of rules to multiple attributes at the same time (like it was in Yii2). Coulb be done with something like:

$rules = [
    new Some(['email', 'emailConfirmation'], [
        new Required(),
        new Email()
    ]),
];

or

$rules = [
    new Some(['field1', 'field2', 'field3', ...], new Required()),
];
What do you get instead?

Now I need to duplicate code like this:

$rules = [
    'field1' => new Required(),
    'field2' => new Required(),
    'field3' => new Required(),
    ...
];
Additional info
Q A
Version 1.4.1
PHP version 8.3
Operating system Linux

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

The issue names no implementation files or tests. Start by locating how rules are assigned to attributes and how existing Required and Email rules are tested; define coverage for applying one ruleset to multiple attributes and verify each named attribute receives the expected validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
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.