<?php

// FooVendor/BarBundle/EventListener/CommentListener.php
use FooVendorBarBundleEventCommentEvent;

class CommentListener
{
    protected $mailer;

    public function __construct(Swift_Mailer $mailer)
    {
        $this->mailer = $mailer;
    }

    public function onCommentEvent(CommentEvent $event)
    {
        $post = $event->getPost();
        $comment = $event->getComment();

        foreach ($post->getSubscribers() as $subscriber) {
            $message = Swift_Message::newInstance()
                ->setSubject('New comment posted on ' . $post->getTitle())
                ->setFrom('send@example.com')
                ->setTo($subscriber->getEmail())
                ->setBody("Hey, somebody left a new comment on a post you're subscribed to! It says: " . $comment->getBody())
            ;
            $this->mailer->send($message);
        }
    }
}

?>