openclassrooms / akismet
Akismet 库
v2.0.1
2016-12-14 10:33 UTC
Requires
- php: >=5.4
- guzzlehttp/guzzle: ~6.2
Requires (Dev)
- phpunit/phpunit: ~5.5
- satooshi/php-coveralls: dev-master
This package is auto-updated.
Last update: 2024-09-06 23:25: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。该包为此库提供了易于配置的选项。