新增敏感词验证

This commit is contained in:
JaguarJack 2020-06-18 16:29:54 +08:00
parent b4b0d624a6
commit 1f3c025f36
2 changed files with 30 additions and 0 deletions

View File

@ -58,6 +58,7 @@ return [
*/ */
'validates' => [ 'validates' => [
\catcher\validates\Sometimes::class, \catcher\validates\Sometimes::class,
\catcher\validates\SensitiveWord::class,
], ],
/** /**
* 上传设置 * 上传设置

View File

@ -1 +1,30 @@
<?php <?php
namespace catcher\validates;
use catcher\library\Trie;
class SensitiveWord implements ValidateInterface
{
protected $word;
public function type(): string
{
// TODO: Implement type() method.
return 'sensitive_word';
}
public function verify($value): bool
{
$trie = app(Trie::class);
$word = $trie->getSensitiveWords($trie->getTries(), $value, false);
return !$word;
}
public function message(): string
{
// TODO: Implement message() method.
return '内容包含敏感词';
}
}