Code Monkey home page Code Monkey logo

akismetbundle's Introduction

AkismetBundle

SensioLabsInsight Build Status Coverage Status

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.

Installation

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(),
    // ...
);

Configuration

# app/config/config.yml

openclassrooms_akismet:
    key:  %akismet.key%
    blog: %akismet.blog%

Usage

Default Service

$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);

Bridge Service

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');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.