PHPackages                             ayeo/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. ayeo/validator

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

ayeo/validator
==============

Universal and independent validator

1.2.6(5y ago)434.7k↑62.5%11MITPHPPHP &gt;=5.4.0CI failing

Since May 28Pushed 5y ago6 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (13)Used By (1)

Validator
=========

[](#validator)

Independent library allows to simple validation other objects

Install
=======

[](#install)

Using composer

```
composer require ayeo/validator

```

Example objects
===============

[](#example-objects)

Let's consider simplified objects as below

```
class Company
{
    /** @var Address */
    private $address;

    /** @var string */
    public $name;

    /** @var Address */
    public function getAddress()
    {
        return $this->address();
    }
}
```

```
class Address
{
    /** @var string */
    public $street;

    /** @var string */
    public $town;

    /** @var string */
    public $countries;

}
```

Validation rules
================

[](#validation-rules)

To process validation we need to define our rules

```
use Ayeo\Validator\ValidationRules

class CompanyValidationRules extends ValidationRules
{
    public function getRules()
    {
        return
        [
            ['company',
                [
                    ['name', new MinLength(5)],
                    ['address',
                        ['street', new MinLength(5)],
                        ['town', new MinLength(5)],
                        ['country', new OneOf(['USA', 'UK', 'Poland'])]
                    ]
                ]
        ];
    }
}
```

It is not too sophisticated but works just fine. As you can see we are able to validate nested objects. Validator is smart enough to get private and protected properties (if we got getter). Validator usage:

```
$company = new Company;
$company->name = "Test Company";

$validator = new Validator(new CompanyValidationRules);
$isValid = $validator->validate($company);
$errors = $validator->getErrors();
```

Default values
==============

[](#default-values)

Version 1.2 introduced default values support. In order to set default value you need to pass it as third argument. Default value will be used only if field value is null. Be aware that default value as still subject of further validation - if you set invalid default value it will result with error

```
use Ayeo\Validator\ValidationRules

class CompanyValidationRules extends ValidationRules
{
    public function getRules()
    {
        return [['company', [['name', new MinLength(5), "Unknown name"]]];
    }
}
```

Allow null
==========

[](#allow-null)

By default given validator will skip checking in case of null value. Of course you need some of them to check even null value. If constraint class implements CheckNull interface validator will force check field even if it is null. At the moment only NotNull constraint it one of this kind.

Availaible constraints
======================

[](#availaible-constraints)

- Length
- MinLength
- MaxLength
- Integer
- Numeric
- NumericMin
- NumericMax
- NotNull
- NonEmpty
- ArrayOfType
- IsArray
- ClassInstance
- NotClassInstance
- LowerThanField
- NoWhitespace
- Email

Feel free to add some more!

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~191 days

Recently: every ~249 days

Total

12

Last Release

1908d ago

Major Versions

v1.2.x-dev → v2.0.x-dev2018-10-18

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

v2.0.x-devPHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e19f24a709e451d9017d8748a8f42a03a3974a9ab065aeda950ec96b229d7f4?d=identicon)[ayeo](/maintainers/ayeo)

---

Top Contributors

[![ayeo](https://avatars.githubusercontent.com/u/60191?v=4)](https://github.com/ayeo "ayeo (4 commits)")[![ppietak](https://avatars.githubusercontent.com/u/4834548?v=4)](https://github.com/ppietak "ppietak (3 commits)")[![Greg0](https://avatars.githubusercontent.com/u/1397756?v=4)](https://github.com/Greg0 "Greg0 (1 commits)")[![jaco](https://avatars.githubusercontent.com/u/60188?v=4)](https://github.com/jaco "jaco (1 commits)")[![maureis](https://avatars.githubusercontent.com/u/6088053?v=4)](https://github.com/maureis "maureis (1 commits)")

---

Tags

validator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ayeo-validator/health.svg)

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[seld/jsonlint

JSON Linter

1.3k217.8M205](/packages/seld-jsonlint)[composer/spdx-licenses

SPDX licenses list and validation library.

1.4k184.2M25](/packages/composer-spdx-licenses)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15644.9M188](/packages/laminas-laminas-validator)

PHPackages © 2026

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