PHP code example of andrey-helldar / blacklist-client

1. Go to this page and download the library: Download andrey-helldar/blacklist-client 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/ */

    

andrey-helldar / blacklist-client example snippets


/*
 * DATABASE
 * [email protected] - exists
 * [email protected] - 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('[email protected]');
/* GuzzleHttp\Exception\ClientException with 423 code and content:
 *
 * {"error":{"code":400,"msg":["Checked [email protected] 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;
        }
    }
}

use Helldar\BlacklistClient\Facades\Client;

return Client::store('[email protected]', '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('[email protected]', 'email');

return $item->expired_at; // 2019-09-27 23:25:27

php artisan vendor:publish --provider="Helldar\BlacklistClient\ServiceProvider"