ez-php / validation
Validation module for the ez-php framework — rule-based validator with database-backed unique/exists rules and optional i18n support
0.2.0
2026-03-15 03:47 UTC
Requires
- php: ^8.5
- ez-php/framework: 0.*
- ez-php/i18n: 0.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
README
Validation module for the ez-php framework — rule-based validator with database-backed unique/exists rules and optional i18n support.
Requirements
- PHP 8.5+
- ez-php/framework ^1.0
Installation
composer require ez-php/validation
Optionally install ez-php/i18n for localised error messages:
composer require ez-php/i18n
Usage
use EzPhp\Validation\Validator; $validator = Validator::make( data: ['email' => 'alice@example.com', 'age' => 17], rules: [ 'email' => 'required|email', 'age' => 'required|integer|min:18', ], ); if ($validator->fails()) { $errors = $validator->errors(); // ['age' => ['The age must be at least 18.']] } // Or throw on failure: $validator->validate(); // throws ValidationException
Supported rules
| Rule | Description |
|---|---|
required |
Field must be present and non-empty |
string |
Must be a string |
integer |
Must be an integer |
email |
Must be a valid email address |
min:n |
Minimum value (numeric) or length (string) |
max:n |
Maximum value (numeric) or length (string) |
regex:/pattern/ |
Must match the given regex |
unique:table,column |
Value must not exist in the given DB column |
exists:table,column |
Value must exist in the given DB column |
With i18n
Pass a Translator instance to receive messages in the configured locale:
$translator = $app->make(\EzPhp\I18n\Translator::class); $validator = Validator::make($data, $rules, translator: $translator);
License
MIT — Andreas Uretschnig