switon/validation
Composer 安装命令:
composer require switon/validation
包简介
Attribute-driven validation with normalization and locale-aware error messages for Switon Framework
README 文档
README
Switon's validation layer for constraint attributes, typed input conversion, and localized error messages.
Highlights
- Constraint attributes:
Required,Length,Email, and related attributes validate fields directly. - Typed values:
TypeandDefaultscan fill and cast values during validation. - Validation flow: one-shot and manual validation are both supported.
- Localized messages: template files provide per-locale fallback messages and labels.
Installation
composer require switon/validation
Quick Start
use Switon\Validating\Attribute\Defaults; use Switon\Validating\Attribute\Email; use Switon\Validating\Attribute\Length; use Switon\Validating\Attribute\Required; use Switon\Validating\Attribute\Type; use Switon\Core\Attribute\Autowired; use Switon\Validating\ValidatorInterface; final class UserService { #[Autowired] protected ValidatorInterface $validator; public function register(array $input): array { return $this->validator->validateValues($input, [ 'email' => [new Required(), new Email()], 'name' => [new Required(), new Length(2, 32)], 'age' => [new Defaults(18), new Type('int')], ]); } }
Docs: https://docs.switon.dev/latest/validation
License
MIT.
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-07