File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ .. index ::
2
+ single: Notifier; Events
3
+
4
+ Using Events
5
+ ============
6
+
7
+ The Transport class of the Notifier component allows you to optionally hook
8
+ into the lifecycle via events. Instead of reinventing
9
+ the wheel, it uses the Symfony EventDispatcher component to do the work::
10
+
11
+
12
+ The ``MessageEvent `` Event
13
+ --------------------------
14
+
15
+ **Typical Purposes **: Doing something before the message is send (like logging
16
+ which message is going to be send), or displaying something about the event
17
+ to be executed.
18
+
19
+ Just before executing any command, the ``MessageEvent `` event is
20
+ dispatched. Listeners receive a
21
+ :class: `Symfony\\ Component\\ Notifier\\ Event\\ MessageEvent ` event::
22
+
23
+ use Symfony\Component\Notifier\Event\MessageEvent;
24
+
25
+ $dispatcher->addListener(MessageEvent::class, function (MessageEvent $event) {
26
+ // gets the message instance
27
+ $message = $event->getMessage();
28
+
29
+ // log something
30
+ $this->logger(sprintf("Message with subject: %s will be send to %s, $message->getSubject(), $message->getRecipientId()");
31
+ });
32
+
33
+ The ``SentMessageEvent `` Event
34
+ --------------------------
35
+
36
+ **Typical Purposes **: Doing something when the message is sent (like retrieve the id returned
37
+ when the message is sent).
38
+
You can’t perform that action at this time.
0 commit comments