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

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

crodas/validator
================

Validation library

v0.2.2(10y ago)32.2k2BSD-4-ClausePHP

Since Oct 25Pushed 10y ago1 watchersCompare

[ Source](https://github.com/crodas/Validator)[ Packagist](https://packagist.org/packages/crodas/validator)[ RSS](/packages/crodas-validator/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (15)Used By (2)

Validator [![Build Status](https://camo.githubusercontent.com/3ac24e439e667f7d3a1c44fcf597c830f4463947c68a14d657245b3767c909f2/68747470733a2f2f7472617669732d63692e6f72672f63726f6461732f56616c696461746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/crodas/Validator)
=========================================================================================================================================================================================================================================================================================

[](#validator-)

Generate static validators to validate your data in PHP. *Static* means that the rules are defined offline, then the library generates code to run the validations. We don't run any checking at runtime.

If you need to define validation rules on the fly, for instance you have a CMS or something like that, then this library would be of little help (unless you call the `crodas\Validator\Builder` manually), in that case I would recommend to take a look at @Respect's [validation library](https://github.com/respect/Validation) which has been an inspiration for this library.

How to installed
----------------

[](#how-to-installed)

---

The easiest way of install the package is using Composer:

```
composer "crodas/validator":\*

```

How to use it
-------------

[](#how-to-use-it)

### Our object

[](#our-object)

All the validation rules are defined used Annotatios, it should be like this:

```
/** @Validate */
class User
{
    /** @Between([18, 99], "Invalid age range, it should be between 18-99") */
    protected $age;

    /**
     * @NoWhitespace("Spaces are not allowed")
     * @MinLength([5], "{$value} is too short")
     * @MaxLength([10], "{$value} is too long")
     */
    public $username;
}
```

### Easy way

[](#easy-way)

You can just call the `crodas/Validator/validate` function, it will take care of the everything else.

```
$user = new User;
$user->age = 17;
$user->username = "invalid username";
if (!crodas\Validator\validate($user, $errors)) {
    echo "There has been an error";
    foreach ($errors as $property => $error) {
        echo "...\n";
    }
    exit;
}
```

### Hard way

[](#hard-way)

You can also generate the validation object reading the PHP files from a given directory. This project exposes it's engine and compile so this can be done very easily. The first thing you have to do is create the Validator object.

```
require "vendor/autoload.php";

$val = new crodas\Validator\Init("/classes/", "/tmp/foo.php");
```

The validator object would look for classes defined inside `/classes/` and its subdirectories the first time. It would then load classes with @Validate annotation in it.

To validate an object you would have to do something like this.

```
$errors = $val->validate(new User);
if (!empty($errors)) {
  foreach ($errors as $field => $exception) {
     echo "{$field} is not valid ( {$exception} )\n";
  }
}
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

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

Total

13

Last Release

3702d ago

### Community

Maintainers

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

---

Top Contributors

[![crodas](https://avatars.githubusercontent.com/u/36463?v=4)](https://github.com/crodas "crodas (117 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/crodas-validator/health.svg)](https://phpackages.com/packages/crodas-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)
