codercms / form-request
A lightweight FormRequest implementation inspired by Laravel && Symfony
Installs: 305
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/codercms/form-request
Requires
- php: >=7.4
- symfony/validator: ^5.0
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2025-09-29 02:42:59 UTC
README
A lightweight FormRequest implementation with data normalization. Based on symfony/validator.
Comparison on 10000 iterations with complex validation rules:
- Faster then Laravel FormRequest about 3.8 times
- Faster then Symfony Form about 9.7 times
Usage (look at tests for more examples):
<?php declare(strict_types=1); use Codercms\FormRequest\RequestNormalizer; use Codercms\FormRequest\ValueNormalizer; use Codercms\FormRequest\ValidationException; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Validation; class TestFormRequest extends \Codercms\FormRequest\FormRequest { protected function setupRules(): Assert\Collection { return new Assert\Collection( [ 'is_active' => new Assert\Optional( new Assert\Type('bool') ), ] ); } } $formRequest = new TestFormRequest( new RequestNormalizer(new ValueNormalizer()), Validation::createValidator() ); $data = [/* your incoming data here */]; try { $normalizedData = $formRequest->handle($data); } catch (ValidationException $e) { $errors = $e->getViolationList(); // handle errors here }