PHP code example of gsteel / akismet

1. Go to this page and download the library: Download gsteel/akismet 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/ */

    

gsteel / akismet example snippets




use GSteel\Akismet\Client;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;

$client = new Client(
    'myApiKey',
    'https://my-website.example.com',
    Psr18ClientDiscovery::find(),
    Psr17FactoryDiscovery::findRequestFactory(),
    Psr17FactoryDiscovery::findStreamFactory()
);

// Check the validity of your API key

$result = $client->verifyKey();
assert($result === true);




use GSteel\Akismet\AkismetClient;
use GSteel\Akismet\CommentParameters;
use GSteel\Akismet\CommentType;

assert($client instanceof AkismetClient);

$parameters = (new CommentParameters())
    ->withComment('Some comment Content', CommentType::contactForm())
    ->withRequestParams($_SERVER['REMOTE_ADDR']);
    
$result = $client->check($parameters);

assert($result->isSpam());




use GSteel\Akismet\CommentParameters;
use Psr\Http\Message\ServerRequestInterface;

assert($request instanceof ServerRequestInterface);

$parameters = CommentParameters::fromRequest($request);




use GSteel\Akismet\AkismetClient;
use GSteel\Akismet\Result;

assert($client instanceof AkismetClient);

$parameters = CommentParameters::fromRequest($request);
$result = $client->check($parameters);

// Result is incorrectly classified as spam:
$client->submitHam($result->parameters());

// Result is incorrectly classified as ham:
$client->submitSpam($result->parameters());




use GSteel\Akismet\Result;

assert($result instanceof Result);

$jsonString = json_encode($result);

$hydratedResult = Result::fromJsonString($jsonString);



$config = [
    'akismet' => [
        'key' => 'Your API Key',
        'website' => 'https://you.example.com',
    ],
];