Skip to content

Commit 287b258

Browse files
committed
init doc
1 parent 4c6b780 commit 287b258

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

notifier/events.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+

0 commit comments

Comments
 (0)