PHPackages                             genai/validation - 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. genai/validation

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

genai/validation
================

Attribute-based validation compiled to a reflection-free validator. Put #\[NotBlank\]/#\[Email\]/#\[Length\]/#\[Pattern\]/#\[Matches\] on a #\[Validate\] form class; a build-time processor bakes the rules into Cache\\Validation. At runtime, validate a populated form object -&gt; a field=&gt;error map, no reflection. PHP 5.3-safe runtime.

v1.0.1(1mo ago)0115↓20.8%Apache-2.0PHPPHP &gt;=5.3.0CI passing

Since Jul 3Pushed 1mo agoCompare

[ Source](https://github.com/GenAIIO/php-validation)[ Packagist](https://packagist.org/packages/genai/validation)[ RSS](/packages/genai-validation/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

genai/validation
================

[](#genaivalidation)

Attribute-based validation, **compiled to a reflection-free validator** — the same build-time pattern as `genai/dto` / `genai/sql-mapper`.

Define a form
-------------

[](#define-a-form)

```
use GenAI\Validation\Attribute\Validate;
use GenAI\Validation\Attribute\NotBlank;
use GenAI\Validation\Attribute\Email;
use GenAI\Validation\Attribute\Length;
use GenAI\Validation\Attribute\Matches;

#[Validate]
class SignupForm
{
    #[NotBlank]                 public $name;
    #[NotBlank] #[Email]        public $email;
    #[Length(min: 6)]           public $password;
    #[Matches('password')]      public $passwordConfirm;
}
```

The `#[...]` lines are build-only (comments on PHP 5.3).

**Public or private fields.** Public properties are read directly. A `private`/ `protected` field is read through a `getXxx()`/`isXxx()` getter (auto-detected at compile; a private field without one is a build error) — same approach as `#[Dto]`. Note the *runtime* still has to populate the form, so a private field also needs a setter or constructor; public props are the least ceremony.

Use it
------

[](#use-it)

```
// bind() populates declared fields from the request (public prop set directly,
// private via its setXxx() — where the form can normalize), then validate().
$form   = $validator->bind(new SignupForm(), $request->getParsedBody());
$errors = $validator->validate($form);   // array('email' => 'Please enter a valid email address.')
if (!$errors) {
    // valid — use $form->getEmail(), etc.
}
```

`bind()` only touches declared fields (no mass-assignment of stray request keys) and is reflection-free (it uses the same compiled field map as `validate()`). Put trimming/normalization in the form's setters and it runs automatically on bind. Inject `GenAI\Validation\Validator` — it's auto-wired (the package's bundle provides the bean as the compiled `Cache\Validation`). One first message per field.

Constraints
-----------

[](#constraints)

AttributeChecks`#[NotBlank]`not null / not empty (after trim)`#[Email]`valid email`#[Length(min, max)]`string length in range (either bound optional)`#[Pattern('/regex/')]`matches a PCRE regex`#[Matches('otherField')]`equals another field (e.g. password confirm)All except `#[NotBlank]` **pass an empty value**, so combine `#[NotBlank] #[Email]`to both require *and* format-check. Every constraint takes an optional `message:` to override the default.

How it compiles
---------------

[](#how-it-compiles)

`ValidationProcessor` reads each `#[Validate]` class's property constraints (matched via the `Constraint` base + `IS_INSTANCEOF`) and bakes a rule table into `Cache\Validation extends GenAI\Validation\Validator`. At runtime the `Validator`reads the form's public props and walks that table with a `type` switch — no reflection. `Cache\Validation` is always generated (empty when no forms), so the bean always resolves.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance90

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

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

Total

2

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/25e5bd31b5dd70d47cbdc738bded06dbabfba3d584acce63c2c4b4fb7847f39d?d=identicon)[jinnguyen](/maintainers/jinnguyen)

---

Top Contributors

[![linhnnmt](https://avatars.githubusercontent.com/u/162856460?v=4)](https://github.com/linhnnmt "linhnnmt (7 commits)")

### Embed Badge

![Health badge](/badges/genai-validation/health.svg)

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

###  Alternatives

[toplan/laravel-sms

A mobile phone number validation solution based on laravel

83580.2k2](/packages/toplan-laravel-sms)[hyperf/validation

hyperf validation

122.2M213](/packages/hyperf-validation)[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)

PHPackages © 2026

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