particleflux/yii2-blocklist-validator

Validate attributes against a blocklist

Maintainers

Package info

github.com/particleflux/yii2-blocklist-validator

pkg:composer/particleflux/yii2-blocklist-validator

Statistics

Installs: 2 084

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.2.0 2024-11-25 15:56 UTC

This package is auto-updated.

Last update: 2026-03-29 01:03:31 UTC


README

Packagist Version (custom server) Packagist PHP Version build codecov

A Yii2 validator to block certain values

Installation

composer require particleflux/yii2-blocklist-validator

Usage

BlockListFileValidator

Block attribute values contained in a file.

public function rules(): array
{
    return [
        ['username', BlockListFileValidator::class, 'file' => '@app/config/bad-usernames.txt'],
    ];
}

Some of the behavior can be fine-tuned:

public function rules(): array
{
    return [
        [
            'username',
            BlockListFileValidator::class,
            'file' => '@app/config/bad-usernames.txt'   // the path to the blocklist file, can contain aliases
            'strict' => true,           // whether to do strict comparison (default: false)
            'useCache' => true,         // use cache component defined in 'cache' (default: true)
            'cacheTtl' => 60,           // cache TTL (default: null, meaning the component default)
            'cache' => 'customCache',   // cache component to use (default 'cache')
        ],
    ];
}