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

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

maatify/validation
==================

Schema-based validation library for PHP applications

v1.0.0(2mo ago)027↓100%MITPHPPHP ^8.2CI passing

Since Mar 5Pushed 2mo agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Validation Module
=================

[](#validation-module)

[![Latest Version](https://camo.githubusercontent.com/fd31ce24478298c2de295b9dd362528a19285dafe987719f9e5642b53d2c0452/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6161746966792f76616c69646174696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/maatify/validation)[![PHP Version](https://camo.githubusercontent.com/eacf2e63c08d3dd27c60a158df0d690c76718ebfe2e106dfcd16e4abfc9d0b23/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6161746966792f76616c69646174696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/maatify/validation)[![License](https://camo.githubusercontent.com/4590d19c6b8cb2f13236693d3f87ea98465dc73171be2e76362189872be7ef5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d6161746966792f76616c69646174696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](LICENSE)

[![PHPStan](https://camo.githubusercontent.com/f85016b73718ab38275b913dafed1c1ce7f287c3c2ec319445bc29011149f408/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d344538434145)](https://camo.githubusercontent.com/f85016b73718ab38275b913dafed1c1ce7f287c3c2ec319445bc29011149f408/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d344538434145)

[![Changelog](https://camo.githubusercontent.com/32f7664d004132f7e0fb111b5e01bd7270705d1e7247db502287d51910c04cb9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4368616e67656c6f672d566965772d626c7565)](CHANGELOG.md)[![Security](https://camo.githubusercontent.com/a150750c8b2c6ca6209aa80bdf220d2f0950b984df64c1b859a46ee9152570f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53656375726974792d506f6c6963792d696d706f7274616e74)](SECURITY.md)

[![Monthly Downloads](https://camo.githubusercontent.com/76170b4e55cd44c21a69dd1525c36aa97cc0fdbfcb00fb2a5908cdbd288a5831/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6161746966792f76616c69646174696f6e3f6c6162656c3d4d6f6e74686c79253230446f776e6c6f61647326636f6c6f723d303041384538)](https://camo.githubusercontent.com/76170b4e55cd44c21a69dd1525c36aa97cc0fdbfcb00fb2a5908cdbd288a5831/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6161746966792f76616c69646174696f6e3f6c6162656c3d4d6f6e74686c79253230446f776e6c6f61647326636f6c6f723d303041384538)[![Total Downloads](https://camo.githubusercontent.com/c27ede1299453b5ebe51228e8801102a9b9661ffda5715445161b7996ec66176/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6161746966792f76616c69646174696f6e3f6c6162656c3d546f74616c253230446f776e6c6f61647326636f6c6f723d324141394530)](https://camo.githubusercontent.com/c27ede1299453b5ebe51228e8801102a9b9661ffda5715445161b7996ec66176/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6161746966792f76616c69646174696f6e3f6c6162656c3d546f74616c253230446f776e6c6f61647326636f6c6f723d324141394530)

A **type-safe, framework-agnostic input validation module** built on top of
**Respect/Validation**, designed for clean architecture, strict static analysis, and future extraction as a standalone library.

This module is designed for standalone usage and is **not coupled** to:

- Authentication
- Authorization (Guards)
- Domain Logic
- HTTP Frameworks (Slim, PSR-7)
- UI / Templates

---

🎯 Goals
-------

[](#-goals)

- Centralize **input validation** in a clean, reusable layer
- Eliminate duplicated validation logic in controllers
- Enforce **type-safety** using DTOs and Enums
- Pass **PHPStan level max** with zero suppressions
- Prepare the module for future extraction as a standalone package

---

🧱 Architectural Principles
--------------------------

[](#-architectural-principles)

### 1. Validation is a Cross-Cutting Concern

[](#1-validation-is-a-cross-cutting-concern)

Validation:

- Touches Controllers and Requests
- Does **not** belong to Domain, Auth, or Guards
- Produces **no side effects** (no audit, no security events)

### 2. Validation ≠ Authorization

[](#2-validation--authorization)

- Validation checks **data correctness**
- Authorization checks **permissions**
- They are strictly separated

### 3. No Strings, No Magic

[](#3-no-strings-no-magic)

- All error codes are **Enums**
- All responses are **DTOs**
- No hard-coded strings in schemas

---

📁 Directory Structure
---------------------

[](#-directory-structure)

```

src/
├── Contracts/
│   ├── SchemaInterface.php
│   ├── ValidatorInterface.php
│   ├── ErrorMapperInterface.php
│   └── SystemErrorMapperInterface.php
│
├── DTO/
│   ├── ValidationResultDTO.php
│   └── ApiErrorResponseDTO.php
│
├── Enum/
│   ├── ValidationErrorCodeEnum.php
│   ├── AuthErrorCodeEnum.php
│   └── HttpStatusCodeEnum.php
│
├── ErrorMapper/
│   ├── ApiErrorMapper.php
│   └── SystemApiErrorMapper.php
│
├── Rules/
│   ├── EmailRule.php
│   ├── PasswordRule.php
│   └── RequiredStringRule.php
│
├── Schemas/
│   ├── AbstractSchema.php
│   ├── AuthLoginSchema.php
│   └── AdminCreateSchema.php
│
└── Validator/
└── RespectValidator.php

```

---

📦 Dependency
------------

[](#-dependency)

This module relies on:

```
composer require respect/validation
```

No other external dependencies are required.

---

🧩 Core Concepts
---------------

[](#-core-concepts)

### 1️⃣ Rules

[](#1️⃣-rules)

Rules are **pure validation units** built on Respect/Validation.

- One rule = one responsibility
- No HTTP, no DTOs, no Domain logic
- Return `Validatable` via docblocks for PHPStan compatibility

Example:

```
EmailRule::rule()
```

---

### 2️⃣ Schemas

[](#2️⃣-schemas)

Schemas describe **request-level validation**.

- One schema per endpoint / use-case
- Declarative rules
- No try/catch duplication
- All schemas extend `AbstractSchema`

Example:

```
final class AuthLoginSchema extends AbstractSchema
{
    protected function rules(): array
    {
        return [
            'email' => [v::email(), ValidationErrorCodeEnum::INVALID_EMAIL],
            'password' => [CredentialInputRule::rule(), ValidationErrorCodeEnum::INVALID_PASSWORD],
        ];
    }
}
```

---

### 3️⃣ ValidationResultDTO

[](#3️⃣-validationresultdto)

Schemas always return a `ValidationResultDTO`:

- `isValid(): bool`
- `getErrors(): array`

No exceptions are thrown for invalid input.

---

### 4️⃣ Error Mapping

[](#4️⃣-error-mapping)

Errors are mapped **once** at the system boundary.

- Validation → `ValidationErrorCodeEnum`
- Auth / Guards → `AuthErrorCodeEnum`
- Transport → `HttpStatusCodeEnum`

All errors are converted into a single response shape via:

```
SystemApiErrorMapper
```

---

### 5️⃣ ApiErrorResponseDTO

[](#5️⃣-apierrorresponsedto)

All API error responses are represented as a DTO:

```
ApiErrorResponseDTO
```

- Contains HTTP status
- Contains error code
- Contains structured field errors
- No arrays returned directly from mappers

---

🌐 Typical Flow (API)
--------------------

[](#-typical-flow-api)

1. Controller receives input
2. Schema validates input
3. `ValidationResultDTO` is returned
4. If invalid:

    - Errors mapped via `SystemApiErrorMapper`
    - Controller sends HTTP response
5. If valid:

    - Controller proceeds to Service layer

---

❌ What This Module Does NOT Do
------------------------------

[](#-what-this-module-does-not-do)

- ❌ No authentication logic
- ❌ No authorization checks
- ❌ No audit logging
- ❌ No database access
- ❌ No localization (i18n)
- ❌ No HTTP framework coupling

---

🧪 Static Analysis
-----------------

[](#-static-analysis)

- Designed to pass **PHPStan level max**
- No suppressions
- No dynamic magic exposed to type system
- Respect/Validation handled via docblocks where needed

---

🔮 Future Extensions (Planned)
-----------------------------

[](#-future-extensions-planned)

- Localization mapping (Enum → i18n keys)
- Composite schemas
- Context-aware validation (create vs update)
- Standalone package extraction (`maatify/validation`)
- Shared SuccessResponseDTO for APIs

---

🧠 Architectural Decision (LOCKED)
---------------------------------

[](#-architectural-decision-locked)

> **All input validation must be expressed as Schemas using Rules + Enums, and mapped through a single system-level ErrorMapper. No strings, no duplication, no side effects.**

---

✅ Status
--------

[](#-status)

- Architecture: **LOCKED**
- Implementation: **STABLE**
- PHPStan: **PASS (level max)**
- Ready for reuse and extraction

---

🪪 License
---------

[](#-license)

This library is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.

---

👤 Author
--------

[](#-author)

Engineered by **Mohamed Abdulalim** ([@megyptm](https://github.com/megyptm)) Backend Lead &amp; Technical Architect

---

🤝 Contributors
--------------

[](#-contributors)

Special thanks to the Maatify.dev engineering team and all open-source contributors. Contributions are welcome.

---

 Built with ❤️ by [Maatify.dev](https://www.maatify.dev) — Unified Ecosystem for Modern PHP Libraries

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance87

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

65d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a885a0810f2762586520ab284c9019aaf0b650b53cdf2a6c13ea10931bb7795?d=identicon)[Maatify](/maintainers/Maatify)

---

Top Contributors

[![megyptm](https://avatars.githubusercontent.com/u/33574895?v=4)](https://github.com/megyptm "megyptm (2 commits)")

---

Tags

clean-architecturemaatifymaatify-devmaatify-ecosystemphpphp-validationrespect-validationschema-validationvalidationvalidation-library

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65378.4k9](/packages/awurth-slim-validation)[progsmile/request-validator

Simple PHP Request Validator

33113.3k1](/packages/progsmile-request-validator)[resultsystems/validation

Inspired 'KennedyTedesco Validation' - The power of 'Respect Validation' on Laravel.

2832.4k4](/packages/resultsystems-validation)

PHPackages © 2026

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