Skip to content

Commit 400a3c6

Browse files
authored
Merge pull request #617 from FriendsOfSymfony/scope
Fix scope error on Symfony 3
2 parents b6a6fa4 + 047c6d4 commit 400a3c6

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the FOSCommentBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace FOS\CommentBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
17+
/**
18+
* SpamDetectionPass
19+
*/
20+
class SpamDetectionPass implements CompilerPassInterface
21+
{
22+
/**
23+
* {@inheritDoc}
24+
*/
25+
public function process(ContainerBuilder $container)
26+
{
27+
// Symfony 2.3 BC
28+
if (class_exists('Symfony\Component\HttpFoundation\RequestStack')) {
29+
return;
30+
}
31+
32+
if ($container->hasDefinition('fos_comment.spam_detection.comment.akismet')) {
33+
$definition = $container->getDefinition('fos_comment.spam_detection.comment.akismet');
34+
$definition->setScope('request');
35+
}
36+
37+
if ($container->hasDefinition('fos_comment.listener.comment_spam')) {
38+
$definition = $container->getDefinition('fos_comment.listener.comment_spam');
39+
$definition->setScope('request');
40+
}
41+
}
42+
}

FOSCommentBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use FOS\CommentBundle\DependencyInjection\Compiler\SecurityPass;
1515
use FOS\CommentBundle\DependencyInjection\Compiler\SortingPass;
16+
use FOS\CommentBundle\DependencyInjection\Compiler\SpamDetectionPass;
1617
use Symfony\Component\HttpKernel\Bundle\Bundle;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819

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

3132
$container->addCompilerPass(new SecurityPass());
3233
$container->addCompilerPass(new SortingPass());
34+
$container->addCompilerPass(new SpamDetectionPass());
3335
}
3436
}

Resources/config/spam_detection.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
<services>
1717

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

22-
<service id="fos_comment.listener.comment_spam" class="FOS\CommentBundle\EventListener\CommentSpamListener" scope="request">
22+
<service id="fos_comment.listener.comment_spam" class="FOS\CommentBundle\EventListener\CommentSpamListener">
2323
<tag name="kernel.event_subscriber" />
2424
<argument type="service" id="fos_comment.spam_detection.comment" />
2525
</service>

0 commit comments

Comments
 (0)