DEV Community

Cover image for small/forms

Posted on


Here is a small library to validate and transform api data.

It can read Symfony atrtributes and you can normalize input data with modifiers like this :

namespace App\DTO;

use Small\Forms\Modifier\NullIfEmptyModifier;use Small\Forms\ValidationRule\ValidateNotEmpty;
use Small\Forms\ValidationRule\ValidateGreaterOrEqual;

class Person

    private string $name;
    private int $age;


try {

    $form = \Small\Forms\FormBuilder::createFromAdapter(
        new \Small\Forms\Adapter\AnnotationAdapter($person)
    )->validate($messages = new \Small\Collection\Collection\StringCollection())
    ->hydrate($employe = new App\Entity\Employe());

} catch (\Small\Forms\ValidationRule\Exception\ValidationFailException) {
    return new \Symfony\Component\HttpFoundation\JsonResponse($messages, \Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST);
Enter fullscreen mode Exit fullscreen mode

You can check it on on my gitlab server :
And packagist :

Top comments (0)