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

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

macocci7/purephp-validation
===========================

illuminate/validation wrapper for pure php.

0.0.5(1y ago)036[2 PRs](https://github.com/macocci7/purephp-validation/pulls)MITPHPPHP &gt;=8.2CI failing

Since Apr 27Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/macocci7/purephp-validation)[ Packagist](https://packagist.org/packages/macocci7/purephp-validation)[ RSS](/packages/macocci7-purephp-validation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (8)Used By (0)

Purephp Validation
==================

[](#purephp-validation)

1. Features
-----------

[](#1-features)

`Purephp Validation` is a standalone library to use the [Illuminate\\Validation](https://github.com/illuminate/validation) package outside the Laravel framework.

This library is based on [jeffochoa/validator-factory](https://github.com/jeffochoa/validator-factory),

This library is customized to use with static calls, like a Laravel Facade:

```
$validator = Validator::make(
    $data,
    $rules,
    $messages,
    $attributes,
);
```

It also supports `Password` rule object and `File` rule object.

```
$validator = Validator::make(
    data: $data,
    rules: [
        'password' => [
            'required',
            Password::min(8),
        ],
        'attachment' => [
            'required',
            File::image(),
        ],
    ];
);
```

Additionally and uniquely, `Instance` rule object is supported.

```
$validator = Validator::make(
    data: [
        'prop1' => new Instance([]),
        'prop2' => 'Instance',
        'prop3' => fn () => true,
    ],
    rules: [
        'prop1' => Instance::of(Instance::class),
        'prop2' => Instance::of([
            Instance::class,
            Validator::class,
            (fn () => true)::class,
        ]),
        'prop3' => Instance::of('Closure'),
    ],
);
```

2. Contents
-----------

[](#2-contents)

- [1. Features](#1-features)
- 2. Contents
- [3. Requirements](#3-requirements)
- [4. Installation](#4-installation)
- [5. Usage](#5-usage)
    - [5.1. Basic Usage](#51-basic-usage)
    - [5.2. Setting Traslations Root Path and Language](#52-setting-translations-root-path-and-language)
    - [5.3. Using Passowrd Rule Object](#53-using-password-rule-object)
    - [5.4. Using File Rule Object](#54-using-file-rule-object)
    - [5.5. Using Instance Rule Object](#55-using-instance-rule-object)
- [6. Examples](#6-examples)
- [7. LICENSE](#7-license)

3. Requirements
---------------

[](#3-requirements)

- PHP 8.2 or later
- Composer installed

4. Installation
---------------

[](#4-installation)

```
composer require macocci7/purephp-validation
```

5. Usage
--------

[](#5-usage)

### 5.1. Basic Usage

[](#51-basic-usage)

First, import `autoload.php` into your code (in `src/` folder) like this:

```
require_once __DIR__ . '/../vendor/autoload.php';
```

Then, create a new instance of the `Illuminate\Validation\Validator` as follows:

```
use Macocci7\PurephpValidation\ValidatorFactory as Validator;

$validator = Validator::make(
    data: [
        'name' => 'foo',
        'email' => 'foo@example.com',
        'password' => 'Passw0rd',
    ],
    rules: [
        'name' => 'required|string|min:3|max:40',
        'email' => 'required|email:rfc',
        'password' => 'required|string|min:8|max:16',
    ],
);
```

Now, you can check the validation results:

```
if ($validator->fails()) {
    var_dump($validator->errors()->message);
} else {
    echo "🎊 Passed 🎉" . PHP_EOL;
}
```

You can learn more about writing validation rules at the [Laravel Official Documentation](https://laravel.com/docs/11.x/validation#quick-writing-the-validation-logic).

Here's also an example code for basic usage: [BasicUsage.php](examples/BasicUsage.php)

### 5.2. Setting Translations Root Path and Language

[](#52-setting-translations-root-path-and-language)

You'll probably want to place the `lang` folder somewhere else outside of `vendor/`.

You can set the Translations Root Path before creating an instance of `Validator`:

```
// Set Translations Root Path (optional)
// - The path must end with '/'.
// - 'lang/' folder must be placed under the path.
Validator::translationsRootPath(__DIR__ . '/');
```

You can also set the Language before creating an instance of `Validator`:

```
// Set lang: 'en' as default (optional)
Validator::lang('ja');
```

Here's an example code for setting Translations Root Path and Language: [SetTranslationsRootPath.php](examples/SetTranslationsRootPath.php)

### 5.3. Using Password Rule Object

[](#53-using-password-rule-object)

You can validate passwords using Laravel's `Password` rule object.

```
use Macocci7\PurephpValidation\Rules\PasswordWrapper as Password;

$validator = Validator::make(
    data: [ 'password' => 'pass' ],
    rules: [
        'password' => [
            'required',
            Password::min(8)
                ->max(16)
                // at least one letter
                ->letters()
                // at least one uppercase
                // and at least one lowercase letter
                ->mixedCase()
                // at least one number
                ->numbers()
                // at least one symbol
                ->symbols()
                // not in a data leak
                ->uncompromised(),
        ],
    ],
);
```

You can learn more about Laravel's `Password` rule object at the [Laravel Official Document](https://laravel.com/docs/11.x/validation#validating-passwords).

Here's an example code for using `Password` rule object: [ValidatePassword.php](examples/ValidatePassword.php)

### 5.4. Using File Rule Object

[](#54-using-file-rule-object)

You can validate files using Laravel's `File` rule object.

```
use Illuminate\Validation\Rule;
use Macocci7\PurephpValidation\Rules\FileWrapper as File;
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;

$path = __DIR__ . '/../storage/uploaded/foo.jpg';

$validator = Validator::make(
    data: [
        'photo' => new SymfonyFile($path),
    ],
    rules: [
        'photo' => [
            'required',
            File::image()
                ->min(10)   // kilo bytes
                ->max(144)  // kilo bytes
                ->dimensions(
                    Rule::dimensions()
                        ->maxWidth(200)     // pix
                        ->maxHeight(300)    // pix
                ),
        ],
    ],
);
```

You can learn more about Laravel's `File` rule object at the [Laravel Official Document](https://laravel.com/docs/11.x/validation#validating-files).

Here's an example code for using Laravel's `File` rule object: [ValidateFile.php](examples/ValidateFile.php)

### 5.5. Using Instance Rule Object

[](#55-using-instance-rule-object)

You can validate objects using `Instance` rule object. (unique feature)

By using `Instance::of($class)` method as a rule, you can perform `$value instanceof $class` in the validation.

`Instance::of()` accepts class name(s) as an argument.

```
use Macocci7\PurephpValidation\Rules\Instance;

$validator = Validator::make(
    data: $data,
    rules: [
        'prop1' => Instance::of(Instance::class),
        'prop2' => Instance::of([
            // Macocci7\PurephpValidation\Rules\Instance
            Instance::class,
            // Macocci7\PurephpValidation\ValidatorFactory
            Validator::class,
            // Closure
            (fn () => true)::class,
        ]),
        'prop3' => Instance::of('Closure'),
    ],
);
```

Here's an example code for using `Instance` rule object: [ValidateInstance.php](examples/ValidateInstance.php)

6. Examples
-----------

[](#6-examples)

- [BasicUsage.php](examples/BasicUsage.php)
- [SetTranslationsRootPath.php](examples/SetTranslationsRootPath.php)
- [ValidatePassword.php](examples/ValidatePassword.php)
- [ValidateFile.php](examples/ValidateFile.php)
- [ValidateInstance.php](examples/ValidateInstance.php)

7. LICENSE
----------

[](#7-license)

[MIT](LICENSE)

---

Copyright 2024 - 2025 macocci7.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance58

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

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

Total

5

Last Release

490d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/679ca12d13bd605020204915c2b8790bab7598a987b33bc9f4bcf7c7683d198c?d=identicon)[macocci7](/maintainers/macocci7)

---

Top Contributors

[![macocci7](https://avatars.githubusercontent.com/u/19181121?v=4)](https://github.com/macocci7 "macocci7 (14 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M106](/packages/propaganistas-laravel-phone)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)

PHPackages © 2026

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