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 3mo ago1 watchersCompare

[ Source](https://github.com/ayeo/validator2)[ Packagist](https://packagist.org/packages/ayeo/validator2)[ RSS](/packages/ayeo-validator2/feed)WikiDiscussions master Synced 3d 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

31

—

LowBetter than 68% of packages

Maintenance54

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity40

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://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 (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

[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)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M450](/packages/nette-forms)[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)

PHPackages © 2026

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