PHPackages                             fresh-advance/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. fresh-advance/array-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

fresh-advance/array-validator
=============================

The component validates form data or any given array by provided rule list.

v2.2.0(5y ago)131MITPHPPHP &gt;=7.3

Since Nov 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Fresh-Advance/array-validator)[ Packagist](https://packagist.org/packages/fresh-advance/array-validator)[ RSS](/packages/fresh-advance-array-validator/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (3)Versions (13)Used By (0)

Array Validator
===============

[](#array-validator)

[![Build Status](https://camo.githubusercontent.com/77042304bd2a3c7737c267fea01ed9f00c47649115aa8b6503c62a46ef0c6727/68747470733a2f2f7472617669732d63692e636f6d2f46726573682d416476616e63652f61727261792d76616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Fresh-Advance/array-validator)[![Quality Gate Status](https://camo.githubusercontent.com/b64faf862bb04d6acaaaa9a23a426f43759bee3cb4dc943341a8dd4da8edfc7f/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d46726573682d416476616e63655f61727261792d76616c696461746f72266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Fresh-Advance_array-validator)[![Coverage](https://camo.githubusercontent.com/e7f8288da56f2e35471a9ef1700ec1789b974036cf1599d54c2c9dc6a015b1a1/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d46726573682d416476616e63655f61727261792d76616c696461746f72266d65747269633d636f766572616765)](https://sonarcloud.io/dashboard?id=Fresh-Advance_array-validator)[![Technical Debt](https://camo.githubusercontent.com/e3a4466ff7b4f4cb7604df86289fc60324ff2ac62bc93933b02fb47ff15a55de/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d46726573682d416476616e63655f61727261792d76616c696461746f72266d65747269633d7371616c655f696e646578)](https://sonarcloud.io/dashboard?id=Fresh-Advance_array-validator)[![Packagist](https://camo.githubusercontent.com/b1497156a8664ad99a4ad3babca5e08dea4b5b8d34f14545c8a56458681690bc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66726573682d616476616e63652f61727261792d76616c696461746f722e737667)](https://packagist.org/packages/fresh-advance/array-validator)

Simple form data / any array validation tool.

- Component validates an array by provided rules list.
- Its possible to use multiple configurations of one rule for one field in one validation run.
- Not dependant on other third party components.
- Tested with PHP 7.3 and up, including PHP 8.0. Fits PSR-12 coding style.

Installation
------------

[](#installation)

Installation via composer:

```
composer require fresh-advance/array-validator

```

Usage example
-------------

[](#usage-example)

```
use Sieg\ArrayValidator\Keys;
use Sieg\ArrayValidator\Rule;
use Sieg\ArrayValidator\RuleCase;
use Sieg\ArrayValidator\RuleCaseCollection;
use Sieg\ArrayValidator\Validator;

$configurationExample = new RuleCaseCollection(
    new RuleCase(
        new Keys\All(),
        new Rule\LengthRange(5, 7)
    ),
    new RuleCase(
        new Keys\Collection('field1', 'field3'),
        new Rule\Expression('/value\d+/')
    ),
    new RuleCase(
        new Keys\Expression('/2$/'),
        new Rule\Expression('/value\d+/'),
        'Special message'
    )
);

$dataExample = [
    'field1' => 'value1',
    'field2' => 'something'
];

$validator = new Validator($configurationExample);
$errors = $validator->validate($dataExample);
if (empty($errors)) {
    // array fits validation configuration
    echo 'ok';
} else {
    print_r($errors);
}
```

Gives validation errors with fields as keys:

```
Array
(
    [field2] => Array
        (
            [0] => VALIDATOR_RULE_LENGTH_TOO_HIGH
            [1] => Special message
        )

    [field3] => Array
        (
            [0] => VALIDATOR_RULE_EXPRESSION_MATCH_FAILED
        )
)

```

Predefined Rules
----------------

[](#predefined-rules)

There are some basic rules implemented with the component:

- **Callback(closure $closure)**

    - Takes Closure as parameter. **$key** and **$data** will be sent to Closure.
- **EqualsTo(mixed $value)**

    - Check if value is equal to Rule $value parameter.
- **EqualsToKey(string $key)**

    - Check if value is equal to other key value.
- **Expression(string $regex)**

    - Takes regex as parameter.
- **Filter(int $filterRule, array $filterOptions)**

    - Rule uses `filter_var` function for validating the value.
    - Takes PHP filter constants to apply as first param:
        - FILTER\_VALIDATE\_EMAIL
        - FILTER\_VALIDATE\_FLOAT
        - FILTER\_VALIDATE\_INT
        - FILTER\_VALIDATE\_IP
        - FILTER\_VALIDATE\_MAC
        - FILTER\_VALIDATE\_REGEXP
        - FILTER\_VALIDATE\_URL
    - Takes `filter_var` options array as second param.
    - Refer to `filter_var` function documentation for more [information](http://php.net/manual/en/function.filter-var.php)
- **InArray(array $choices)**
- **Length(int $length)**
- **LengthRange(int $min, int $max)**
- **Max(int $max)**
- **MaxLength(int $max)**
- **Min(int $min)**
- **MinLength(int $min)**
- **Range(int $min, int $max)**
- **Required**

    - Check if the field exists and not empty

Create and use custom Rules
---------------------------

[](#create-and-use-custom-rules)

- Custom rule should extend `\Sieg\ArrayValidator\Rule\AbstractRule`
- Use it as regular rules whose comes with the component.
- Validator catches `\Sieg\ArrayValidator\Exception\RuleFailed` type Exceptions for setting field error messages.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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

Every ~118 days

Recently: every ~280 days

Total

11

Last Release

1927d ago

Major Versions

v0.5.2 → v1.0.02018-05-24

v1.0.0 → v2.0.02020-12-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf25d2c148579fed45c9fcaa19c3de35a750fa774812fbb5c30149f42f470215?d=identicon)[sieg](/maintainers/sieg)

---

Top Contributors

[![Sieg](https://avatars.githubusercontent.com/u/98882?v=4)](https://github.com/Sieg "Sieg (86 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fresh-advance-array-validator/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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