codercms/form-request
Composer 安装命令:
composer require codercms/form-request
包简介
A lightweight FormRequest implementation inspired by Laravel && Symfony
README 文档
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 }
统计信息
- 总下载量: 309
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-08