Skip to content

Commit 83ff99a

Browse files
author
Hugo Hamon
committed
[AppBundle] encourage the use of EventSubscriber everywhere.
1 parent 2f5ab24 commit 83ff99a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

app/config/services.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,5 @@ services:
111111
AppBundle\EventListener\RedirectToPreferredLocaleSubscriber:
112112
$locales: '%app_locales%'
113113

114-
# Event Listeners are classes that listen to one or more specific events.
115-
# Those events are defined in the tags added to the service definition.
116-
# See http://symfony.com/doc/current/event_dispatcher.html#creating-an-event-listener
117-
AppBundle\EventListener\CommentNotificationListener:
114+
AppBundle\EventListener\CommentNotificationSubscriber:
118115
$sender: '%app.notifications.email_sender%'
119-
# The "method" attribute of this tag is optional and defaults to "on + camelCasedEventName"
120-
# If the event is "comment.created" the method executed by default is "onCommentCreated()".
121-
tags:
122-
- { name: kernel.event_listener, event: comment.created, method: onCommentCreated }

src/AppBundle/EventListener/CommentNotificationListener.php renamed to src/AppBundle/EventListener/CommentNotificationSubscriber.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace AppBundle\EventListener;
1313

1414
use AppBundle\Entity\Comment;
15+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1516
use Symfony\Component\EventDispatcher\GenericEvent;
1617
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1718
use Symfony\Component\Translation\TranslatorInterface;
@@ -21,7 +22,7 @@
2122
*
2223
* @author Oleg Voronkovich <oleg-voronkovich@yandex.ru>
2324
*/
24-
class CommentNotificationListener
25+
class CommentNotificationSubscriber implements EventSubscriberInterface
2526
{
2627
/**
2728
* @var \Swift_Mailer
@@ -95,4 +96,11 @@ public function onCommentCreated(GenericEvent $event)
9596
// See http://symfony.com/doc/current/email/dev_environment.html#viewing-from-the-web-debug-toolbar
9697
$this->mailer->send($message);
9798
}
99+
100+
public static function getSubscribedEvents()
101+
{
102+
return [
103+
'comment.created' => 'onCommentCreated',
104+
];
105+
}
98106
}

0 commit comments

Comments
 (0)