Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 74aa75a

Browse filesBrowse files
committed
feat(notifier): add SentMessage additional info
1 parent dfcc142 commit 74aa75a
Copy full SHA for 74aa75a

File tree

3 files changed

+57
-0
lines changed
Filter options

3 files changed

+57
-0
lines changed

‎src/Symfony/Component/Notifier/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/CHANGELOG.md
+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add `SentMessage` additional info array
8+
49
7.2
510
---
611

‎src/Symfony/Component/Notifier/Message/SentMessage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Message/SentMessage.php
+18
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ class SentMessage
1818
{
1919
private ?string $messageId = null;
2020

21+
/**
22+
* @param array $info attaches any Transport-related information to the sent message
23+
*/
2124
public function __construct(
2225
private MessageInterface $original,
2326
private string $transport,
27+
private array $info = [],
2428
) {
2529
}
2630

@@ -43,4 +47,18 @@ public function getMessageId(): ?string
4347
{
4448
return $this->messageId;
4549
}
50+
51+
/**
52+
* Returns any arbitrary data attached to the message.
53+
*
54+
* @param string|null $key if null, the whole info array will be returned, else returns the info value or null
55+
*/
56+
public function getInfo(?string $key = null): mixed
57+
{
58+
if (null !== $key) {
59+
return $this->info[$key] ?? null;
60+
}
61+
62+
return $this->info;
63+
}
4664
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Message;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Message\SentMessage;
16+
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
17+
18+
class SentMessageTest extends TestCase
19+
{
20+
public function test()
21+
{
22+
$originalMessage = new DummyMessage();
23+
24+
$sentMessage = new SentMessage($originalMessage, 'any', ['foo' => 'bar']);
25+
$sentMessage->setMessageId('the_id');
26+
27+
$this->assertSame($originalMessage, $sentMessage->getOriginalMessage());
28+
$this->assertSame('any', $sentMessage->getTransport());
29+
$this->assertSame('the_id', $sentMessage->getMessageId());
30+
$this->assertSame(['foo' => 'bar'], $sentMessage->getInfo());
31+
$this->assertSame('bar', $sentMessage->getInfo('foo'));
32+
$this->assertNull($sentMessage->getInfo('not_existing'));
33+
}
34+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.