Validation Overview
antares-validation provides two things: a Hydrator that maps raw arrays to readonly PHP DTOs, and a Validator that checks those DTOs against PHP attributes. All errors are collected before throwing — you always get the full error list, not just the first failure.
composer require fatjon-lleshi/antares-validationThis package has no dependency on the Antares framework core and can be used in any PHP 8.2+ project.
How It Works
Section titled “How It Works”- Annotate a readonly class with
#[Dto]and add validation attributes to its constructor parameters. - Pass raw data (from a request body, form post, etc.) to
$hydrator->hydrate(). - If hydration succeeds, a fully typed DTO is returned. If validation fails, a
ValidationExceptionis thrown with a map of all field errors.
use Antares\Hydration\Hydrator;use Antares\Validation\Validator;
$hydrator = new Hydrator(new Validator());
try { $dto = $hydrator->hydrate(CreateUserRequest::class, $rawData);} catch (ValidationException $e) { $e->getErrors(); // ['email' => ['Must be a valid email address']]} catch (HydrationException $e) { // raw data could not be mapped to the DTO shape}In the framework, the Dispatcher handles this automatically for any parameter typed as a #[Dto] class.