| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 2 | CRAP |  | 0.00% | 0 / 19
CommentListener |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 2 | 12 |  | 0.00% | 0 / 18
__construct(Swift_Mailer $mailer) |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 4
onCommentEvent(CommentEvent $event) |  | 0.00% | 0 / 1 | 6 |  | 0.00% | 0 / 14

1 | <?php
2 |
3 | // FooVendor/BarBundle/EventListener/CommentListener.php
4 | use FooVendorBarBundleEventCommentEvent;
5 |
6 | class CommentListener
7 | {
8 | protected $mailer;
9 |
10 | public function __construct(Swift_Mailer $mailer)
11 | {
12 | $this->mailer = $mailer;
13 | }
14 |
15 | public function onCommentEvent(CommentEvent $event)
16 | {
17 | $post = $event->getPost();
18 | $comment = $event->getComment();
19 |
20 | foreach ($post->getSubscribers() as $subscriber) {
21 | $message = Swift_Message::newInstance()
22 | ->setSubject('New comment posted on ' . $post->getTitle())
23 | ->setFrom('send@example.com')
24 | ->setTo($subscriber->getEmail())
25 | ->setBody("Hey, somebody left a new comment on a post you're subscribed to! It says: " . $comment->getBody())
26 | ;
27 | $this->mailer->send($message);
28 | }
29 | }
30 | }
31 |