vigstudio / akismet
2.0.4
2020-12-12 05:01 UTC
Requires
- php: >=5.4
Requires (Dev)
- satooshi/php-coveralls: dev-master
This package is auto-updated.
Last update: 2024-09-12 12:46:38 UTC
README
这是一个 PHP5 库,它为您的应用程序提供了 Akismet 垃圾邮件保护服务 功能。
安装
安装 Akismet 库的最简单方法是使用 composer。
创建以下 composer.json
文件,并运行 php composer.phar install
命令来安装。
{ "require": { "openclassrooms/akismet": "*" } }
<?php require 'vendor/autoload.php'; use OpenClassrooms\Akismet\Services\AkismetService; //do things
基本用法
AkismetServiceImpl
类需要设置一个客户端以与 Akismet 垃圾邮件保护服务进行通信。此库提供了一个基于 GuzzleHttp\Client 的客户端,尽管您也可以实现自己的客户端。然后,您可以使用 AkismetServiceImpl::setClient()
方法设置客户端。
模型
评论
此库定义了一个 "评论" 接口,必须将其作为参数传递给不同的 AkismetService 方法。
use OpenClassrooms\Akismet\Models\Comment; $comment = new CommentImpl();
评论构建器
此库提供了一个构建器来创建评论
use OpenClassrooms\Akismet\Models\CommentBuilder; $comment = $commentBuilder->create() ->withUserIp(CommentStub::USER_IP) ->withUserAgent(CommentStub::USER_AGENT) ->withReferrer(CommentStub::REFERRER) ->withPermalink(CommentStub::PERMALINK) ->withAuthorName(CommentStub::AUTHOR_NAME) ->withAuthorEmail(CommentStub::AUTHOR_EMAIL) ->withContent(CommentStub::CONTENT) ->build();
服务
Use OpenClassrooms\Akismet\Services\Impl\AkismetServiceImpl; $akismetService = new AkismetServiceImpl(); // commentCheck method needs only one parameter, which has to be the Comment object if ($akismetService->commentCheck($comment)) { // store the comment and mark it as spam (in case of a misdiagnosis). } else { // store the comment normally }
提交误诊的垃圾邮件和正常邮件,以提高每个人的系统。
$akismetService->submitSpam($comment);
此外
$akismetService->submitHam($comment);
超出此库范围
如果您计划在 Symfony2 项目中使用 Akismet 库,请查看 AkismetBundle。 该组件为此库提供了一个易于配置的选项。