Skip to content

Commit

Permalink
Merge pull request #617 from FriendsOfSymfony/scope
Browse files Browse the repository at this point in the history
Fix scope error on Symfony 3
  • Loading branch information
XWB authored Oct 23, 2017
2 parents b6a6fa4 + 047c6d4 commit 400a3c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
42 changes: 42 additions & 0 deletions DependencyInjection/Compiler/SpamDetectionPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* This file is part of the FOSCommentBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace FOS\CommentBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
* SpamDetectionPass
*/
class SpamDetectionPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
// Symfony 2.3 BC
if (class_exists('Symfony\Component\HttpFoundation\RequestStack')) {
return;
}

if ($container->hasDefinition('fos_comment.spam_detection.comment.akismet')) {
$definition = $container->getDefinition('fos_comment.spam_detection.comment.akismet');
$definition->setScope('request');
}

if ($container->hasDefinition('fos_comment.listener.comment_spam')) {
$definition = $container->getDefinition('fos_comment.listener.comment_spam');
$definition->setScope('request');
}
}
}
2 changes: 2 additions & 0 deletions FOSCommentBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\CommentBundle\DependencyInjection\Compiler\SecurityPass;
use FOS\CommentBundle\DependencyInjection\Compiler\SortingPass;
use FOS\CommentBundle\DependencyInjection\Compiler\SpamDetectionPass;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand All @@ -30,5 +31,6 @@ public function build(ContainerBuilder $container)

$container->addCompilerPass(new SecurityPass());
$container->addCompilerPass(new SortingPass());
$container->addCompilerPass(new SpamDetectionPass());
}
}
4 changes: 2 additions & 2 deletions Resources/config/spam_detection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

<services>

<service id="fos_comment.spam_detection.comment.akismet" class="FOS\CommentBundle\SpamDetection\AkismetSpamDetection" scope="request" public="false">
<service id="fos_comment.spam_detection.comment.akismet" class="FOS\CommentBundle\SpamDetection\AkismetSpamDetection" public="false">
<argument type="service" id="ornicar_akismet" />
</service>

<service id="fos_comment.listener.comment_spam" class="FOS\CommentBundle\EventListener\CommentSpamListener" scope="request">
<service id="fos_comment.listener.comment_spam" class="FOS\CommentBundle\EventListener\CommentSpamListener">
<tag name="kernel.event_subscriber" />
<argument type="service" id="fos_comment.spam_detection.comment" />
</service>
Expand Down

0 comments on commit 400a3c6

Please sign in to comment.