particleflux / yii2-blocklist-validator
Validate attributes against a blocklist
0.2.0
2024-11-25 15:56 UTC
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
- yiisoft/yii2: ^2.0
Requires (Dev)
- infection/infection: ^0.27.6
- phpcompatibility/php-compatibility: dev-develop
- phpmd/phpmd: ^2.14
- phpro/grumphp: ^2.1
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^10.4
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-12-25 16:16:00 UTC
README
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') ], ]; }