vigihdev/yii2-bridge-validator
Composer 安装命令:
composer require vigihdev/yii2-bridge-validator
包简介
Custom validation rules and enhanced validator for Yii2 with database-aware validators and i18n support
README 文档
README
Custom validation rules and enhanced validator for Yii2 with database-aware validators and i18n support.
Features
- 🔍 Database-aware validation rules (ExistsRecord, UniqueRecord)
- 🌐 Multilingual validation messages with i18n support
- 🏗️ Service container integration
- 📝 Enhanced validation with custom rules
- ⚡ High performance with caching support
- 🧪 Comprehensive test coverage
Installation
composer require vigihdev/yii2-bridge-validator
Quick Start
Basic Usage
use VigihDev\Yii2Bridge\Validator\Rules\{ExistsRecordRule, UniqueRecordRule}; use Yiisoft\Validator\Rule\{Required, Length, Email}; class User extends BaseActiveRecord { #[Required] #[Length(min: 3, max: 255)] #[UniqueRecordRule(targetClass: User::class, targetAttribute: 'username')] public string $username = ''; #[Required] #[Email] public string $email = ''; }
Database Validation Rules
// Check if record exists #[ExistsRecordRule( targetClass: User::class, targetAttribute: 'id', message: 'User not found' )] public int $user_id; // Ensure uniqueness #[UniqueRecordRule( targetClass: User::class, targetAttribute: 'email', message: 'Email already exists' )] public string $email;
Available Rules
- ExistsRecordRule - Validates that a record exists in database
- UniqueRecordRule - Ensures field value is unique in database
Testing
Run the test suite:
composer test
Run development server:
composer run server
Requirements
- PHP 8.1 or higher
- Yiisoft Validator ^2.5
- Yiisoft Cache ^3.1
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Vigih Dev
- Email: vigihdev@gmail.com
- GitHub: @vigihdev
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-01