perf / spam-detection
此包已被放弃,不再维护。未建议替代包。
允许从可疑表单提交中检测垃圾信息。
2.0.0
2023-11-01 03:13 UTC
Requires
- php: >=8.2
Requires (Dev)
- ext-xdebug: *
- phing/phing: ^2.16
- phpmd/phpmd: ^2.8
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.4
- rector/rector: ^0.18.6
- squizlabs/php_codesniffer: ^3.5
README
允许检测来自联系表单等的垃圾信息。
安装
composer require perf/spam-detection
配置
实现一个垃圾关键词库,例如这个
use perf\SpamDetection\SpamKeyword; use perf\SpamDetection\SpamKeywordRepositoryInterface; class SpamKeywordRepository implements SpamKeywordRepositoryInterface { public function getSpamKeywords(): iterable { return [ new SpamKeyword('viagra', 150), new SpamKeyword('casino', 100), ]; } }
用法
现在您可以检测垃圾信息了
use perf\SpamDetection\SpamEvaluator; $spamEvaluator = new SpamEvaluator( new SpamKeywordRepository(), 100 // Threshold ); $submittedContent = 'Buy Viagra, and then go to the casino.' $outcome = $spamEvaluator->evaluate($submittedContent); if ($outcome->isSpam()) { echo "This is definitely spam."; }