Custom validation rules and enhanced validator for Yii2 with database-aware validators and i18n support.
- 🔍 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
 
composer require vigihdev/yii2-bridge-validatoruse 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 = '';
}// 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;- ExistsRecordRule - Validates that a record exists in database
 - UniqueRecordRule - Ensures field value is unique in database
 
Run the test suite:
composer testRun development server:
composer run server- PHP 8.1 or higher
 - Yiisoft Validator ^2.5
 - Yiisoft Cache ^3.1
 
This project is licensed under the MIT License - see the LICENSE file for details.
Vigih Dev
- Email: vigihdev@gmail.com
 - GitHub: @vigihdev
 
Contributions are welcome! Please feel free to submit a Pull Request.