particleflux/yii2-blocklist-validator

验证属性是否在黑名单中

0.1.0 2024-04-30 18:05 UTC

This package is auto-updated.

Last update: 2024-09-30 18:57:04 UTC


README

Packagist Version (custom server) Packagist PHP Version build Maintainability Test Coverage

一个用于阻止特定值的 Yii2 验证器

安装

composer require particleflux/yii2-blocklist-validator

使用方法

BlockListFileValidator

阻止文件中包含的属性值。

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

一些行为可以进行微调

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')
        ],
    ];
}