File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ CHANGELOG
5
5
---
6
6
7
7
* Add ` Dsn::getBooleanOption() `
8
+ * Add ` info ` property in ` SentMessage `
8
9
9
10
7.2
10
11
---
Original file line number Diff line number Diff line change @@ -18,9 +18,13 @@ class SentMessage
18
18
{
19
19
private ?string $ messageId = null ;
20
20
21
+ /**
22
+ * @param array $info attaches any Transport-related information to the sent message
23
+ */
21
24
public function __construct (
22
25
private MessageInterface $ original ,
23
26
private string $ transport ,
27
+ private array $ info = [],
24
28
) {
25
29
}
26
30
@@ -43,4 +47,18 @@ public function getMessageId(): ?string
43
47
{
44
48
return $ this ->messageId ;
45
49
}
50
+
51
+ /**
52
+ * Returns extra info 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
+ }
46
64
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments