新增敏感词验证
This commit is contained in:
parent
b4b0d624a6
commit
1f3c025f36
@ -58,6 +58,7 @@ return [
|
|||||||
*/
|
*/
|
||||||
'validates' => [
|
'validates' => [
|
||||||
\catcher\validates\Sometimes::class,
|
\catcher\validates\Sometimes::class,
|
||||||
|
\catcher\validates\SensitiveWord::class,
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* 上传设置
|
* 上传设置
|
||||||
|
@ -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 '内容包含敏感词';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user