Skip to content

A SOLID validation library, flexible and extendible.

License

Notifications You must be signed in to change notification settings

Phauthentic/validator

Repository files navigation

Phauthentic Validator

PHP >= 8.0 phpstan Level 8 License: MIT

A SOLID validation library that also tries to do KISS.

  • Designed with maximum flexibility for customization in mind.
  • Tries to be as easy to use and set up as possible.
  • Doesn't include message translations intentionally - single responsibility principle - but provides the flexibility to hook your own system in.
  • Provides a way to customize the error result.
  • It is not exception driven as some other libs.
  • No further dependencies.
  • Framework-agnostic

Example

This is a very simple example. Please read the documentation.

$fieldBuilder = FieldBuilder::create(new FieldCollection());
$fieldBuilder->add('project.id', NotEmpty::NAME);
$fieldBuilder->add('project.name', Between::NAME, [3,10]);
$fieldBuilder->add('project.tasks.*.title', NotEmpty::NAME);
$fieldCollection = $fieldBuilder->getFieldCollection();

$validator = new Validator(
    $fieldCollection,
    (new ValidatorFactory())->createRuleCollection(),
    new ErrorCollection(),
    new GlossaryMessageFormatter()
);

if (!$result->isValid()) {
    var_dump($result->getErrors()->toArray());
}

Documentation

License

The MIT License (MIT)

  • Copyright (c) 2016-2019 Muhammad Syifa
  • Copyright (c) 2021 Dave Redfern
  • Copyright (c) 2022 Florian Krämer