denismitr/spam-detector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

denismitr/spam-detector

Composer 安装命令:

composer require denismitr/spam-detector

包简介

PHP Spam Detector

README 文档

README

Author

Denis Mitrofanov

Installation

composer require denismitr/spam-detector

Usage

You can pass as many inspections as you want to the Denismitr\Spam\Spam class constructor. Every inspection must implement Denismitr\Spam\Contracts\Inspection interface. Right now, out of the box, you get 6 of them:

  • Denismitr\Spam\Inspections\AsciiOnly
  • Denismitr\Spam\Inspections\YahooCustomerSupport
  • Denismitr\Spam\Inspections\RussianForbiddenWords
  • Denismitr\Spam\Inspections\RussianBadWords
  • Denismitr\Spam\Inspections\KeyHeldDown
  • Denismitr\Spam\Inspections\EnglishForbiddenWords

An example of usage:

$text = "Some text to check";

$spam = new Spam([
    YahooCustomerSupport::class,
    RussianForbiddenWords::class,
    RussianBadWords::class,
    KeyHeldDown::class
]);

try {
    $spam->detect($text);
} catch(SpamDetected $e) {
    // Do stuff
}

or to see if any of the given fields contain spam use ```detectAny`` method

try {
    $spam->detectAny([
        'title' => 'Some title...',
        'body' => 'Some body...'
    ]);
} catch(SpamDetected $e) {
    // Do stuff
}

This method will throw if any of the given fields contain spam.

And, of course, if you need, another method detectAll will throw if all fields contain spam:

try {
    $spam->detectAll([
        'title' => 'Some title...',
        'body' => 'Some body...'
    ]);
} catch(SpamDetected $e) {
    // Do stuff
}

Another usecase is when you want to check against only one inspection. For this case there is a static method inspect that accepts a string for a haystack and the Inspection instance like so:

$text = 'Some text to check';

try {
    Spam::inspect($text, new KeyHeldDown);
} catch(SpamDetected $e) {
    // Do stuff
}

You can easily add your own inspections. They must implement Inspection interface. That looks like so:

interface Inspection
{
    /**
     * @param string $text
     * @return void
     */
    public function detect(string $text);
}

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固