andrey-helldar / blacklist-client
v2.2.1
2020-12-30 19:48 UTC
Requires
- php: ^7.1.3|^8.0
- ext-json: *
- ext-mbstring: *
- andrey-helldar/blacklist-core: ^2.0
Requires (Dev)
- phpunit/phpunit: ^8.0
Suggests
- andrey-helldar/blacklist-server: The blacklist server package
README
用于连接黑名单服务器的黑名单客户端包。
内容
安装
要获取 Laravel Blacklist Client 的最新版本,只需使用 Composer 依赖项目
composer require andrey-helldar/blacklist-client
当然,您也可以手动更新 require 块并运行 composer update
,如果这样选择的话
{ "require": { "andrey-helldar/blacklist-client": "^2.0" } }
现在,您还可以发布配置文件以更改实现(例如,将接口更改为特定类)
php artisan vendor:publish --provider="Helldar\BlacklistClient\ServiceProvider"
使用
首先查看 配置。
检查 / 存在
要检查数据库中是否存在垃圾邮件发送者,需要传递数据类型和值
/* * DATABASE * foo@example.com - exists * bar@example.com - not exists */ use Helldar\BlacklistClient\Facades\Client; return Client::check('http://example.com'); // false return Client::check('192.168.1.1'); // false return Client::check('+0 (000) 000-00-00'); // false return Client::check('foo@example.com'); /* GuzzleHttp\Exception\ClientException with 423 code and content: * * {"error":{"code":400,"msg":["Checked foo@example.com was found in our database.]}} */
例如
use GuzzleHttp\Exception\ClientException; use Helldar\BlacklistClient\Facades\Client; class Foo { public function store(array $data) { if (! $this->isSpammer($data['email'])) { // storing data } } private function isSpammer(string $value): bool { try { return Client::check($value); } catch (ClientException $exception) { return true; } } }
存储
要将垃圾邮件发送者存储到数据库中,请使用 facade 的 Client
的 store
方法
use Helldar\BlacklistClient\Facades\Client; return Client::store('foo@example.com', 'email'); return Client::store('http://example.com', 'url'); return Client::store('192.168.1.1', 'ip'); return Client::store('+0 (000) 000-00-00', 'phone');
例如
use Helldar\BlacklistClient\Facades\Client; $item = Client::store('foo@example.com', 'email'); return $item->expired_at; // 2019-09-27 23:25:27
许可证
此包按照 MIT 许可证 发布。