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

dev-main 2025-11-01 17:56 UTC

This package is auto-updated.

Last update: 2025-11-01 17:56:38 UTC


README

PHP Version License Tests

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.