switon/validation

Attribute-driven validation with normalization and locale-aware error messages for Switon Framework

Maintainers

Package info

github.com/switon-php/validation

Documentation

pkg:composer/switon/validation

Statistics

Installs: 35

Dependents: 5

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 02:16:41 UTC


README

CI PHP 8.3+

Switon's validation layer for constraint attributes, typed input conversion, and localized error messages.

Highlights

  • Constraint attributes: Required, Length, Email, and related attributes validate fields directly.
  • Typed values: Type and Defaults can fill and cast values during validation.
  • Validation flow: one-shot and manual validation are both supported.
  • Localized messages: template files provide per-locale fallback messages and labels.

Installation

composer require switon/validation

Quick Start

use Switon\Validating\Attribute\Defaults;
use Switon\Validating\Attribute\Email;
use Switon\Validating\Attribute\Length;
use Switon\Validating\Attribute\Required;
use Switon\Validating\Attribute\Type;
use Switon\Core\Attribute\Autowired;
use Switon\Validating\ValidatorInterface;

final class UserService
{
    #[Autowired] protected ValidatorInterface $validator;

    public function register(array $input): array
    {
        return $this->validator->validateValues($input, [
            'email' => [new Required(), new Email()],
            'name' => [new Required(), new Length(2, 32)],
            'age' => [new Defaults(18), new Type('int')],
        ]);
    }
}

Docs: https://docs.switon.dev/latest/validation

License

MIT.