PHPackages                             sovngare/yii2-array-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sovngare/yii2-array-validator

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

sovngare/yii2-array-validator
=============================

Array validator for for the Yii framework

v1.0(5y ago)1743—0%MITPHP

Since Dec 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Sovngare/yii2-array-validator)[ Packagist](https://packagist.org/packages/sovngare/yii2-array-validator)[ RSS](/packages/sovngare-yii2-array-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Installation
============

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

```
composer require sovngare/yii2-array-validator

```

Usage
=====

[](#usage)

Use class: `sovngare\validators\ArrayValidator`

Example №1
----------

[](#example-1)

Validate true if property "fields" will be array.

```
public function rules()
{
    return [
        ['fields', 'required'],
        ['fields', ArrayValidator::class]
    ];
}
```

Example №2
----------

[](#example-2)

Validate true if status\[code\] key will be integer in the range 100 and 500.

```
public function rules()
{
    return [
        ['fields', ArrayValidator::class, 'key' => 'status.code', 'rules' => [
            ['integer', 'min' => 100, 'max' => 500]
        ]]
    ];
}
```

Example №3
----------

[](#example-3)

By default key label is "Attribute". Model errors log:

```
{
    "fields": [
        "Attribute must be no less than 100."
    ]
}
```

To change label you must send param label:

```
public function rules()
{
    return [
        ['fields', ArrayValidator::class, 'key' => 'status.code', 'rules' => [
            ['integer', 'min' => 100, 'max' => 500]
        ], 'label' => 'status_code']
    ];
}
```

Model errors log now:

```
{
    "fields": [
        "Status Code must be no less than 100."
    ]
}
```

Validate images
---------------

[](#validate-images)

Data from client:

```
phone:7087952412
fields[name]:Sovngare
fields[avatar]:(\yii\web\UploadedFile)

```

Model:

```
class TestModel extends Model
{
    public $phone;
    public $fields;

    public function rules()
    {
        return [
            [['phone', 'fields'], 'required'],
            ['fields', ArrayValidator::class, 'key' => 'name', 'rules' => [
                ['required'],
                ['string', 'length' => [4, 16]]
            ], 'label' => 'name'],
            ['fields', ArrayValidator::class, 'key' => 'avatar', 'rules' => [
                ['required'],
                ['image', 'maxSize' => 1024 * 1024 * 3]
            ], 'label' => 'avatar'],
        ];
    }
}
```

Controller

```
public function actionIndex()
{
    $model = new TestModel();
    $model->attributes = Yii::$app->request->getBodyParams();

    if (is_array($model->fields)) {
        $model->fields['avatar'] = UploadedFile::getInstanceByName('fields[avatar]');
    }

    if (!$model->validate()) {
        return $model->errors;
    }

    return $model->attributes;
}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1966d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4529438bbd801c559d3f70130559a6476916568d06783503a55ac9c0b3be35b6?d=identicon)[Sovngare](/maintainers/Sovngare)

---

Top Contributors

[![Sovngare](https://avatars.githubusercontent.com/u/69149622?v=4)](https://github.com/Sovngare "Sovngare (1 commits)")

---

Tags

validatorarraykeyyii2array key validator

### Embed Badge

![Health badge](/badges/sovngare-yii2-array-validator/health.svg)

```
[![Health](https://phpackages.com/badges/sovngare-yii2-array-validator/health.svg)](https://phpackages.com/packages/sovngare-yii2-array-validator)
```

###  Alternatives

[lezhnev74/pasvl

Array Validator (regular expressions for nested array, sort of)

5253.7k3](/packages/lezhnev74-pasvl)[baibaratsky/yii2-serialized-attributes-behavior

Yii2 Serialized Attributes Behavior

1174.1k9](/packages/baibaratsky-yii2-serialized-attributes-behavior)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
