mitsuki/validators

There is no license information available for the latest version (v1.0.0) of this package.

A Symfony Validator–based request validation layer for PHP, providing an abstract RequestValidator and structured ValidationException for HTTP 422 responses.

Maintainers

Package info

github.com/zgeniuscoders/mitsuki-validation

pkg:composer/mitsuki/validators

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-02-16 21:46 UTC

This package is auto-updated.

Last update: 2026-02-16 21:49:57 UTC


README

A lightweight request validation layer built on top of Symfony Validator, designed to work seamlessly with custom HTTP requests in PHP applications.

Features

  • Abstract RequestValidator class that merges query, request body, and files into a single dataset.
  • Easy rule definition via the rules() method using Symfony Constraint objects.
  • Throws a structured ValidationException (HTTP 422) when validation fails.
  • Clean, reusable validators for your API or web controllers.

Installation

Install the package via Composer:

composer require mitsuki/hermite-validators
  1. Create a validator class extending RequestValidator:
use Mitsuki\Hermite\Validators\RequestValidator;
use Symfony\Component\Validator\Constraints as Assert;

class CreateUserRequest extends RequestValidator
{
    public function rules(): array
    {
        return [
            'email' => [new Assert\Email(), new Assert\NotBlank()],
            'age'   => [new Assert\Type('numeric'), new Assert\GreaterThan(17)],
        ];
    }
}
  1. Inject request data (e.g., in tests or controllers) and validate:
$request = new CreateUserRequest();
$request->initialize(
    [], // GET
    ['email' => 'user@example.com', 'age' => 25]
);

$request->validateOrFail(); // Throws ValidationException on failure
  1. Catch and inspect validation errors:
use Mitsuki\Hermite\Validators\Exceptions\ValidationException;

try {
    $request->validateOrFail();
} catch (ValidationException $e) {
    $errors = $e->getErrors();
    // $errors['email'] = 'This value is not a valid email address.'
}