AkismetBundle
The AkismetBundle offers integration of the Akismet Library. Akismet Library is a PHP5 library that provides Akismet Spam Protection service functionality in your application. See Akismet for full details.
This bundle can be installed using composer:
composer require openclassrooms/akismet-bundle
or by adding the package to the composer.json file directly:
{
"require": {
"openclassrooms/akismet-bundle": "*"
}
}
After the package has been installed, add the bundle to the AppKernel.php file:
// in AppKernel::registerBundles()
$bundles = array(
// ...
new OpenClassrooms\Bundle\AkismetBundle\OpenClassroomsAkismetBundle(),
// ...
);
# app/config/config.yml
openclassrooms_akismet:
key: %akismet.key%
blog: %akismet.blog%
$commentBuilder = $container->get('openclassrooms.akismet.models.comment_builder');
$akismet = $container->get('openclassrooms.akismet.services.default_akismet_service');
$comment = $commentBuilder->create()
...
->build();
if ($akismet->commentCheck($comment)) {
// store the comment and mark it as spam (in case of a mis-diagnosis).
} else {
// store the comment normally
}
// and
$akismet->submitSpam($comment);
// and
$akismet->submitHam($comment);
The Bundle integrates a bridge service which gets the Symfony2 requestStack to automatically set the UserIP, UserAgent and Referrer.
<service id="openclassrooms.akismet.services.akismet_service" class="OpenClassrooms\Bundle\AkismetBundle\Services\Impl\AkismetServiceImpl">
<call method="setAkismet">
<argument type="service" id="openclassrooms.akismet.services.default_akismet_service"/>
</call>
<call method="setRequestStack">
<argument type="service" id="request_stack"/>
</call>
</service>
You can use it by getting this service id:
$akismet = $container->get('openclassrooms.akismet.services.akismet_service');
instead of:
$akismet = $container->get('openclassrooms.akismet.services.default_akismet_service');