Search by

assegaiphp / validation

amasiye

Rule- and attribute-based validation for PHP values and AssegaiPHP DTOs.

Package info

github.com/assegaiphp/validation

pkg:composer/assegaiphp/validation

Statistics

Installs: 1 350

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

0.11.0 2026-11-16 11:36 UTC

This package is auto-updated.

Last update: 2026-11-16 15:17:24 UTC


README

AssegaiPHP Logo

Latest release Tests PHP 8.4+ License Status active

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, and integer
  • required, email, domain, and url
  • between, min, max, minLength, and maxLength
  • equalTo, notEqualTo, inList, notInList, and regex

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, and IsString
  • IsArray, IsInt, and IsNumber
  • IsBetween, IsEqualTo, IsEmpty, and IsNotEmpty
  • IsDate, IsDomain, IsEmail, and IsUrl

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.