@@ -111,10 +111,10 @@ that will do the required processing for your message::
111111
112112 class MyMessageHandler
113113 {
114- public function __invoke(MyMessage $message)
115- {
116- // Message processing...
117- }
114+ public function __invoke(MyMessage $message)
115+ {
116+ // Message processing...
117+ }
118118 }
119119
120120Adding Metadata to Messages (Envelopes)
@@ -215,34 +215,34 @@ First, create your sender::
215215
216216 class ImportantActionToEmailSender implements SenderInterface
217217 {
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+ }
246246 }
247247
248248Your own Receiver
@@ -270,30 +270,30 @@ First, create your receiver::
270270
271271 class NewOrdersFromCsvFileReceiver implements ReceiverInterface
272272 {
273- private $serializer;
274- private $filePath;
273+ private $serializer;
274+ private $filePath;
275275
276- public function __construct(SerializerInterface $serializer, string $filePath)
277- {
276+ public function __construct(SerializerInterface $serializer, string $filePath)
277+ {
278278 $this->serializer = $serializer;
279279 $this->filePath = $filePath;
280- }
280+ }
281281
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');
285285
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']);
288288
289- $handler(new Envelope($order));
290- }
291- }
289+ $handler(new Envelope($order));
290+ }
291+ }
292292
293- public function stop(): void
294- {
295- // noop
296- }
293+ public function stop(): void
294+ {
295+ // noop
296+ }
297297 }
298298
299299Receiver and Sender on the same Bus
0 commit comments