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
- 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
Validation:
- Touches Controllers and Requests
- Does not belong to Domain, Auth, or Guards
- Produces no side effects (no audit, no security events)
- Validation checks data correctness
- Authorization checks permissions
- They are strictly separated
- All error codes are Enums
- All responses are DTOs
- No hard-coded strings in schemas
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
This module relies on:
composer require respect/validationNo other external dependencies are required.
Rules are pure validation units built on Respect/Validation.
- One rule = one responsibility
- No HTTP, no DTOs, no Domain logic
- Return
Validatablevia docblocks for PHPStan compatibility
Example:
EmailRule::rule()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],
];
}
}Schemas always return a ValidationResultDTO:
isValid(): boolgetErrors(): array<string, list<ValidationErrorCodeEnum>>
No exceptions are thrown for invalid input.
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:
SystemApiErrorMapperAll 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
-
Controller receives input
-
Schema validates input
-
ValidationResultDTOis returned -
If invalid:
- Errors mapped via
SystemApiErrorMapper - Controller sends HTTP response
- Errors mapped via
-
If valid:
- Controller proceeds to Service layer
- ❌ No authentication logic
- ❌ No authorization checks
- ❌ No audit logging
- ❌ No database access
- ❌ No localization (i18n)
- ❌ No HTTP framework coupling
- Designed to pass PHPStan level max
- No suppressions
- No dynamic magic exposed to type system
- Respect/Validation handled via docblocks where needed
- Localization mapping (Enum → i18n keys)
- Composite schemas
- Context-aware validation (create vs update)
- Standalone package extraction (
maatify/validation) - Shared SuccessResponseDTO for APIs
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.
- Architecture: LOCKED
- Implementation: STABLE
- PHPStan: PASS (level max)
- Ready for reuse and extraction
This library is licensed under the MIT License. See the LICENSE file for details.
Engineered by Mohamed Abdulalim (@megyptm) Backend Lead & Technical Architect https://www.maatify.dev
Special thanks to the Maatify.dev engineering team and all open-source contributors. Contributions are welcome.
Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries