PHPackages                             ayeo/validator2 - 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/validator2

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

ayeo/validator2
===============

Simple validation util

11361[2 PRs](https://github.com/ayeo/validator2/pulls)PHPCI failing

Since Oct 17Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/ayeo/validator2)[ Packagist](https://packagist.org/packages/ayeo/validator2)[ RSS](/packages/ayeo-validator2/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (4)Used By (0)

Alligator
=========

[](#alligator)

[![Build Status](https://camo.githubusercontent.com/d648990591fc9e0fc1910770319957bbc7bb01440abcbc0dee4b79f52e27444a/68747470733a2f2f7472617669732d63692e6f72672f6179656f2f616c6c696761746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ayeo/alligator)[![Coverage](https://camo.githubusercontent.com/b45a93578d654165a4ca7599c608d1bfd3a5b8619b8653d255949c9d9de9e08d/68747470733a2f2f636f6465636f762e696f2f67682f6179656f2f616c6c696761746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/ayeo/alligator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)

[![Logo](alligator.png)](alligator.png)

Notice: This project does not reach stable version yet - use when you know what you are doing

Extremely simple yet powerful validation utility. Alligator is intended to fulfill any kind of resource validation. It is happy to traverse trough nested objects. Alligator also works well with protected/private properties.

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

[](#installation)

```
composer requrie ayeo/alligator
```

Rules
-----

[](#rules)

Alligator use scenario is all about working with entire resource objects. Rules are defined at level of the object also. Lets consider simple example.

```
class Person
{
    /** @var string */
    private $firstname;
    /** @var string */
    private $lastname;
    /** @var int */
    private $age;
    /** @var string */
    private $insuranceNumber;

    ...
    //getters/setters comes here
}
```

Rules by default are defined as simple array (but this is not mandatory - see "Custom format" for more details).

```
$recipe = [
    'firstname' => [
        ['not_null', 'required'],
        ['min_length:5', 'too_short'],
        ['max_length:25', 'too_long'],
        ['letters', 'letters_only']
     ],
    'lastname' => [
        ['not_null', 'required'],
        ['min_length:5', 'too_short'],
        ['max_length:25', 'too_long'],
        ['letters', 'letters_only']
    ],
    'age' =>
        ['integer', 'must_be_integer'], //single rule
    'insuranceNumber' =>
        'age>21' => ['regexp:^[0-4]{4}-[0-4]-{4}$', 'invalid_insurance_number']
]
```

Above rules expect firstname and lastname to be letters only and long between 5 and 25 chars. Age is optional but if set must be integer. Insurance number is required only if age is above 21 and it's defined as an regexp here.

Usage
-----

[](#usage)

Having rules at place we are ready to check what Alligator can do for us.

```
$food = new Person('Rocky', 'Balboa');
$food->setAge(37);
$food->setInsuranceNumber('3423-543');

$alligator = new Alligator();
$result = $alligator->taste($food, $recipe);
$errors = $alligator->getErrors();
```

Errors has same structure as input resource object. (todo: describe collection checking)

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance46

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.8% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/60191?v=4)[ayeo](/maintainers/ayeo)[@ayeo](https://github.com/ayeo)

---

Top Contributors

[![ayeo](https://avatars.githubusercontent.com/u/60191?v=4)](https://github.com/ayeo "ayeo (7 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

utility-libraryvalidation-libraryvalidator

### Embed Badge

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

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

###  Alternatives

[toplan/laravel-sms

A mobile phone number validation solution based on laravel

83580.2k2](/packages/toplan-laravel-sms)[udokmeci/yii2-phone-validator

Modern Yii2 Phone validator wrapper on top of PhoneNumberUtil library also used by Android devices

36227.5k1](/packages/udokmeci-yii2-phone-validator)[snowcap/vat-validation

EU VAT number validation

10112.3k](/packages/snowcap-vat-validation)

PHPackages © 2026

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