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

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

highperapp/validator
====================

High-performance data validation with Rust FFI acceleration, AMPHP parallel processing, and pure PHP fallback

00PHP

Since Oct 3Pushed 7mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

HighPerApp Validator Library
============================

[](#highperapp-validator-library)

A high-performance validation library for the HighPerApp ecosystem with triple-engine architecture: Rust FFI → AMPHP → Pure PHP fallback.

Features
--------

[](#features)

- **Interface-driven architecture** - No abstract classes or final keywords
- **Hybrid engine architecture** - Rust FFI + UV → AMPHP + UV → Pure PHP fallback
- **UV extension detection** - Automatic detection and performance optimization
- **Comprehensive validation middleware** - PSR-15 compatible HTTP middleware
- **Environment-based configuration** - 35+ configuration options via environment variables
- **OWASP security compliance** - Input validation best practices
- **PSR compliance** - PSR-4, PSR-3, PSR-11, PSR-15 compatible
- **Auto-discovery support** - Framework integration ready
- **Comprehensive test coverage** - Unit, integration, and performance tests

Quick Start
-----------

[](#quick-start)

### Installation

[](#installation)

```
composer require highperapp/validator
```

### Build Rust Library (Optional)

[](#build-rust-library-optional)

```
./build.sh
```

### Basic Usage

[](#basic-usage)

```
use HighPerApp\HighPer\Validator\ValidatorServiceProvider;

// Bootstrap the validator
$provider = new ValidatorServiceProvider();
$validator = $provider->bootstrap();

// Simple validation
$result = $validator->validate('test@example.com', 'required|email');

if ($result->isValid()) {
    echo "Valid email!";
} else {
    print_r($result->getErrors());
}

// Multi-field validation
$data = [
    'email' => 'user@example.com',
    'age' => 25,
    'website' => 'https://example.com'
];

$rules = [
    'email' => ['required', 'email'],
    'age' => ['required', 'integer', 'min:18', 'max:120'],
    'website' => ['url']
];

$result = $validator->validateMany($data, $rules);
```

### Middleware Usage

[](#middleware-usage)

```
use HighPerApp\HighPer\Validator\ValidatorServiceProvider;

// Get middleware instance
$provider = new ValidatorServiceProvider();
$middleware = $provider->getMiddleware();

// Add validation rules for specific routes
$middleware->addRouteRule('POST', '/api/users', [
    'body.name' => 'required|string|max:255',
    'body.email' => 'required|email|unique:users',
    'body.age' => 'required|integer|min:18|max:120'
]);

// Use in PSR-15 compatible middleware stack
$middlewareStack = [
    $middleware,
    // ... other middleware
];
```

### Fluent Rule Builder

[](#fluent-rule-builder)

```
use HighPerApp\HighPer\Validator\RuleBuilder;

$rules = RuleBuilder::create()
    ->required()
    ->email(strict: true)
    ->length(min: 5, max: 255)
    ->getRules();

$result = $validator->validate($email, $rules);
```

### Async Validation

[](#async-validation)

```
// Large dataset validation with automatic parallelization
$result = $validator->validateAsync($largeDataset, $rules);
```

Engine Configuration
--------------------

[](#engine-configuration)

### Environment Variables

[](#environment-variables)

```
# Engine preferences
VALIDATOR_PREFERRED_ENGINE=rust_ffi
VALIDATOR_RUST_FFI_ENABLED=true
VALIDATOR_AMPHP_ENABLED=true
VALIDATOR_PURE_PHP_ENABLED=true

# Performance tuning
VALIDATOR_ASYNC_THRESHOLD=50
VALIDATOR_PARALLEL_WORKERS=4

# Validation settings
VALIDATOR_EMAIL_STRICT=true
VALIDATOR_URL_REQUIRE_TLD=true

# Debug settings
VALIDATOR_DEBUG=false
VALIDATOR_LOG_LEVEL=info
```

### Manual Configuration

[](#manual-configuration)

```
$config = [
    'engines' => [
        'rust_ffi' => ['enabled' => true],
        'amphp' => ['enabled' => true, 'workers' => 4],
        'pure_php' => ['enabled' => true],
    ],
    'preferred_engine' => 'rust_ffi',
    'performance' => [
        'async_threshold' => 50,
        'parallel_workers' => 4,
    ],
];

$provider = new ValidatorServiceProvider(config: $config);
```

Available Validation Rules
--------------------------

[](#available-validation-rules)

### Basic Types

[](#basic-types)

- `required` - Field must be present and not empty
- `optional` - Field is optional
- `nullable` - Field can be null
- `string` - Must be a string
- `integer` - Must be an integer
- `float` - Must be a float
- `numeric` - Must be numeric
- `boolean` - Must be a boolean
- `array` - Must be an array

### String Validation

[](#string-validation)

- `email` - Valid email address
- `email:strict` - Strict email validation
- `url` - Valid URL
- `url:require_tld` - URL with TLD requirement
- `regex:/pattern/` - Custom regex pattern
- `length:min,max` - String length validation
- `min:value` - Minimum length/value
- `max:value` - Maximum length/value
- `between:min,max` - Value between min and max

### Lists and Choices

[](#lists-and-choices)

- `in:value1,value2,value3` - Value must be in list
- `not_in:value1,value2` - Value must not be in list

### Dates and Format

[](#dates-and-format)

- `date` - Valid date (Y-m-d format)
- `date:Y-m-d H:i:s` - Custom date format
- `json` - Valid JSON
- `json:max_depth=512` - JSON with depth limit

### Network and Identifiers

[](#network-and-identifiers)

- `ip` - Valid IP address (IPv4 or IPv6)
- `ip:4` - IPv4 only
- `ip:6` - IPv6 only
- `uuid` - Valid UUID
- `uuid:4` - UUID version 4
- `phone` - Valid phone number
- `phone:country=US` - Country-specific phone

### Financial

[](#financial)

- `credit_card` - Valid credit card number (Luhn algorithm)

Engine Information
------------------

[](#engine-information)

### Rust FFI Engine (Performance Level 3)

[](#rust-ffi-engine-performance-level-3)

- **Fastest** - Native Rust implementation
- **Parallel processing** - Automatic batch optimization
- **Advanced validation** - Complex regex and format checking
- **Requirements** - FFI extension, compiled Rust library

### AMPHP Engine (Performance Level 2)

[](#amphp-engine-performance-level-2)

- **amphp/parallel** - AMPHP-based parallel processing
- **Worker pools** - Configurable worker management
- **Good performance** - Balanced speed and compatibility
- **Requirements** - AMPHP packages, pcntl extension

### Pure PHP Engine (Performance Level 1)

[](#pure-php-engine-performance-level-1)

- **Universal compatibility** - Works everywhere
- **No dependencies** - Only standard PHP functions
- **Reliable fallback** - Always available
- **Full featured** - All validation rules supported

Framework Integration
---------------------

[](#framework-integration)

### Laravel

[](#laravel)

```
// In a service provider
public function register()
{
    $this->app->singleton(ValidatorInterface::class, function ($app) {
        $provider = new ValidatorServiceProvider();
        return $provider->bootstrap();
    });
}
```

### Symfony

[](#symfony)

```
# services.yaml
services:
    HighPerApp\HighPer\Validator\Contracts\ValidatorInterface:
        factory: ['@HighPerApp\HighPer\Validator\ValidatorServiceProvider', 'bootstrap']

    HighPerApp\HighPer\Validator\ValidatorServiceProvider: ~
```

### PSR-11 Container

[](#psr-11-container)

```
$container->set(ValidatorInterface::class, function() {
    $provider = new ValidatorServiceProvider();
    return $provider->bootstrap();
});
```

Performance Benchmarks
----------------------

[](#performance-benchmarks)

EngineOperations/secUse CaseRust FFI~50,000+High-throughput APIsAMPHP~15,000+Moderate async workloadsPure PHP~5,000+Standard applicationsBuild Requirements
------------------

[](#build-requirements)

### Rust Library

[](#rust-library)

- Rust 1.70+
- Cargo
- FFI-enabled PHP 8.1+

### PHP Requirements

[](#php-requirements)

- PHP 8.1+
- Composer
- Optional: AMPHP packages for parallel engine

Development
-----------

[](#development)

### Building from Source

[](#building-from-source)

```
# Full build with tests
./build.sh --test

# Debug build with verbose output
./build.sh -t debug -v

# Clean rebuild
./build.sh -c -f

# PHP setup only (skip Rust)
./build.sh --php-only
```

### Running Tests

[](#running-tests)

```
# All tests
./build.sh --test

# Rust tests only
cd rust && cargo test

# PHP tests (if PHPUnit available)
phpunit
```

Security
--------

[](#security)

This library follows OWASP validation guidelines:

- Input length limits
- Regex timeout protection
- Error message sanitization
- No code execution in validation rules
- Secure default configurations

License
-------

[](#license)

MIT License - see LICENSE file

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create feature branch
3. Add tests for new functionality
4. Ensure all tests pass
5. Submit pull request

Support
-------

[](#support)

- GitHub Issues: Report bugs and feature requests
- Documentation: See docs/ directory
- Examples: See examples/ directory

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance44

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/dbe04e216b4fb74f076a82bb6bd06f96faa4066089b33082c43f8c9cf184efbf?d=identicon)[raghuveer](/maintainers/raghuveer)

---

Top Contributors

[![raghuveer](https://avatars.githubusercontent.com/u/999229?v=4)](https://github.com/raghuveer "raghuveer (1 commits)")

### Embed Badge

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

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