-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closed threads should not accept comments
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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\EventListener; | ||
|
||
use FOS\CommentBundle\Events; | ||
use FOS\CommentBundle\Event\CommentEvent; | ||
use FOS\CommentBundle\Model\CommentInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Blames a comment using Symfony2 security component | ||
* | ||
* @author Thibault Duplessis <thibault.duplessis@gmail.com> | ||
*/ | ||
class ClosedThreadListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* Disallows comments in a closed thread. | ||
* | ||
* @param \FOS\CommentBundle\Event\CommentEvent $event | ||
*/ | ||
public function onCommentPersist(CommentEvent $event) | ||
{ | ||
$comment = $event->getComment(); | ||
$thread = $comment->getThread(); | ||
|
||
if (!$thread->isCommentable()) { | ||
throw new \LogicException('Cannot add comment to a closed thread'); | ||
} | ||
} | ||
|
||
static public function getSubscribedEvents() | ||
{ | ||
return array(Events::COMMENT_PRE_PERSIST => 'onCommentPersist'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters