vigihdev / yii2-bridge-validator
Custom validation rules and enhanced validator for Yii2 with database-aware validators and i18n support
Installs: 1
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/vigihdev/yii2-bridge-validator
Requires
- php: ^8.1
- yiisoft/cache: ^3.1
- yiisoft/event-dispatcher: ^1.1
- yiisoft/translator: ^3.1
- yiisoft/translator-message-php: ^1.1
- yiisoft/validator: ^2.5
Requires (Dev)
- phpunit/phpunit: ^10.0
- vigihdev/symfony-bridge-config: dev-main
- vigihdev/yii2-bridge-active-record: dev-main
- vigihdev/yii2-bridge-db: dev-main
This package is auto-updated.
Last update: 2025-11-01 17:56:38 UTC
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.