@@ -111,10 +111,10 @@ that will do the required processing for your message::
111
111
112
112
class MyMessageHandler
113
113
{
114
- public function __invoke(MyMessage $message)
115
- {
116
- // Message processing...
117
- }
114
+ public function __invoke(MyMessage $message)
115
+ {
116
+ // Message processing...
117
+ }
118
118
}
119
119
120
120
Adding Metadata to Messages (Envelopes)
@@ -215,34 +215,34 @@ First, create your sender::
215
215
216
216
class ImportantActionToEmailSender implements SenderInterface
217
217
{
218
- private $mailer;
219
- private $toEmail;
220
-
221
- public function __construct(\Swift_Mailer $mailer, string $toEmail)
222
- {
223
- $this->mailer = $mailer;
224
- $this->toEmail = $toEmail;
225
- }
226
-
227
- public function send(Envelope $envelope): Envelope
228
- {
229
- $message = $envelope->getMessage();
230
-
231
- if (!$message instanceof ImportantAction) {
232
- throw new \InvalidArgumentException(sprintf('This transport only supports "%s" messages.', ImportantAction::class));
233
- }
234
-
235
- $this->mailer->send(
236
- (new \Swift_Message('Important action made'))
237
- ->setTo($this->toEmail)
238
- ->setBody(
239
- '<h1>Important action</h1><p>Made by '.$message->getUsername().'</p>',
240
- 'text/html'
241
- )
242
- );
243
-
244
- return $envelope;
245
- }
218
+ private $mailer;
219
+ private $toEmail;
220
+
221
+ public function __construct(\Swift_Mailer $mailer, string $toEmail)
222
+ {
223
+ $this->mailer = $mailer;
224
+ $this->toEmail = $toEmail;
225
+ }
226
+
227
+ public function send(Envelope $envelope): Envelope
228
+ {
229
+ $message = $envelope->getMessage();
230
+
231
+ if (!$message instanceof ImportantAction) {
232
+ throw new \InvalidArgumentException(sprintf('This transport only supports "%s" messages.', ImportantAction::class));
233
+ }
234
+
235
+ $this->mailer->send(
236
+ (new \Swift_Message('Important action made'))
237
+ ->setTo($this->toEmail)
238
+ ->setBody(
239
+ '<h1>Important action</h1><p>Made by '.$message->getUsername().'</p>',
240
+ 'text/html'
241
+ )
242
+ );
243
+
244
+ return $envelope;
245
+ }
246
246
}
247
247
248
248
Your own Receiver
@@ -270,30 +270,30 @@ First, create your receiver::
270
270
271
271
class NewOrdersFromCsvFileReceiver implements ReceiverInterface
272
272
{
273
- private $serializer;
274
- private $filePath;
273
+ private $serializer;
274
+ private $filePath;
275
275
276
- public function __construct(SerializerInterface $serializer, string $filePath)
277
- {
276
+ public function __construct(SerializerInterface $serializer, string $filePath)
277
+ {
278
278
$this->serializer = $serializer;
279
279
$this->filePath = $filePath;
280
- }
280
+ }
281
281
282
- public function receive(callable $handler): void
283
- {
284
- $ordersFromCsv = $this->serializer->deserialize(file_get_contents($this->filePath), 'csv');
282
+ public function receive(callable $handler): void
283
+ {
284
+ $ordersFromCsv = $this->serializer->deserialize(file_get_contents($this->filePath), 'csv');
285
285
286
- foreach ($ordersFromCsv as $orderFromCsv) {
287
- $order = new NewOrder($orderFromCsv['id'], $orderFromCsv['account_id'], $orderFromCsv['amount']);
286
+ foreach ($ordersFromCsv as $orderFromCsv) {
287
+ $order = new NewOrder($orderFromCsv['id'], $orderFromCsv['account_id'], $orderFromCsv['amount']);
288
288
289
- $handler(new Envelope($order));
290
- }
291
- }
289
+ $handler(new Envelope($order));
290
+ }
291
+ }
292
292
293
- public function stop(): void
294
- {
295
- // noop
296
- }
293
+ public function stop(): void
294
+ {
295
+ // noop
296
+ }
297
297
}
298
298
299
299
Receiver and Sender on the same Bus
0 commit comments