PHP code example of imiphp / imi-email-blacklist

1. Go to this page and download the library: Download imiphp/imi-email-blacklist library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

imiphp / imi-email-blacklist example snippets


[
    \Imi\Email\BlackList\EmailBlackListHandler::class => [
        'handler' => \Imi\Email\BlackList\Handler\RedisHandler::class, // 数据处理器,目前仅支持 Redis,你也可以实现 \Imi\Email\BlackList\IHandler 接口自定义处理器
    ],
    \Imi\Email\BlackList\EmailBlackListCrawler::class => [
        'enable' => true, // 是否启用
        // 采集器列表
        // 你也可以实现 \Imi\Email\BlackList\Contract\IEmailBlackListCrawler 接口自定义采集器
        'crawlers' => [
            \Imi\Email\BlackList\IvoloDisposableEmailDomainsCrawler::class, // 数据来源:https://github.com/ivolo/disposable-email-domains/raw/master/index.json
        ],
    ],
    // handler 配置
    \Imi\Email\BlackList\Handler\RedisHandler::class => [
        'key' => 'imi:email:blacklist', // 存储数据的键名
        'poolName' => null, // 连接池
    ],
]

$handler = \Imi\Email\BlackList\Util\EmailBlackListUtil::getHandler();
$handler->add(['example.com']); // 批量增加
$handler->remove(['example.com']); // 批量删除
$handler->clear(); // 清空
$handler->has('example.com'); // 是否存在
$handler->count(); // 统计数量
$handler->list(); // 获取列表
$handler->list('.com'); // 关键词搜索
// 分页
// 注意:RedisHandler 返回数据数量可能不一定等于 $count
$page = 1;
$count = 10;
$handler->list('', $page, $count);



declare(strict_types=1);

namespace app\Module\Service;

use Imi\Email\BlackList\Validate\Annotation\EmailBlackList;
use Imi\Validate\Annotation\AutoValidation;

class TestService
{
    /**
     * @AutoValidation
     *
     * @EmailBlackList(name="email")
     */
    public function testEmail(string $email): void
    {
    }
}

// 不在黑名单中返回 true,否则返回 false
\Imi\Email\BlackList\Util\EmailBlackListUtil::validateEmail('[email protected]');