assegaiphp / validation
Rule- and attribute-based validation for PHP values and AssegaiPHP DTOs.
Requires
- php: >=8.4
- arubacao/tld-checker: ^1.2
- giggsey/libphonenumber-for-php: ^8.13
Requires (Dev)
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-16 15:17:24 UTC
README
AssegaiPHP Validation
Rule- and attribute-based validation for PHP values and AssegaiPHP DTOs.
assegaiphp/validation provides a standalone validator and the property attributes used by Core's DTO validation path. The package intentionally focuses on validation; request binding and response handling remain Core responsibilities.
Requirements
- PHP 8.4 or newer
Installation
composer require 'assegaiphp/validation:~0.11.0'
Validate a value
use Assegai\Validation\Validator; $validator = new Validator(); if (!$validator->validate('developer@example.com', 'required|email')) { $errors = $validator->getErrors(); }
The validator accepts pipe-separated rule names. Its registered shorthand rules are:
alpha,alphaNum,string,numeric, andintegerrequired,email,domain, andurlbetween,min,max,minLength, andmaxLengthequalTo,notEqualTo,inList,notInList, andregex
Add a custom rule
Custom rules implement IValidationRule and can be registered by name:
use Assegai\Validation\Interfaces\IValidationRule; use Assegai\Validation\Validator; final class EvenNumberRule implements IValidationRule { public function passes(mixed $value): bool { return is_int($value) && $value % 2 === 0; } public function getErrorMessage(): string { return 'The value must be an even integer.'; } } $validator = new Validator(); $validator->addRule('even', EvenNumberRule::class); $valid = $validator->validate(4, 'even');
DTO attributes
Core can validate public DTO properties using the package's native PHP attributes. The current property-validation surface includes:
IsAlpha,IsAlphanumeric,IsAscii, andIsStringIsArray,IsInt, andIsNumberIsBetween,IsEqualTo,IsEmpty, andIsNotEmptyIsDate,IsDomain,IsEmail, andIsUrl
See the AssegaiPHP guide for request binding, DTO hydration, validation pipes, and generated OpenAPI schemas.
Contributing
For contribution and pull request conventions, see Commit and PR Guidelines.
License
This package is released under the MIT license.