From d54febf322639125e278ff70c0e4327a92d1b765 Mon Sep 17 00:00:00 2001 From: Sven Scholz Date: Wed, 2 Apr 2025 17:40:01 +0200 Subject: [PATCH] Notifier mercure7.3 --- .../Component/Notifier/Bridge/Mercure/CHANGELOG.md | 5 +++++ .../Component/Notifier/Bridge/Mercure/MercureOptions.php | 7 +++++++ .../Notifier/Bridge/Mercure/MercureTransport.php | 2 ++ .../Notifier/Bridge/Mercure/Tests/MercureOptionsTest.php | 4 +++- .../Bridge/Mercure/Tests/MercureTransportTest.php | 8 ++++---- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/Mercure/CHANGELOG.md b/src/Symfony/Component/Notifier/Bridge/Mercure/CHANGELOG.md index 1f2b652ac20ea..956a1d641042e 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mercure/CHANGELOG.md +++ b/src/Symfony/Component/Notifier/Bridge/Mercure/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.3 +--- + +* Add `content` option + 5.3 --- diff --git a/src/Symfony/Component/Notifier/Bridge/Mercure/MercureOptions.php b/src/Symfony/Component/Notifier/Bridge/Mercure/MercureOptions.php index e47a0113cd34b..4f3f80c0d7649 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mercure/MercureOptions.php +++ b/src/Symfony/Component/Notifier/Bridge/Mercure/MercureOptions.php @@ -29,6 +29,7 @@ public function __construct( private ?string $id = null, private ?string $type = null, private ?int $retry = null, + private ?array $content = null, ) { $this->topics = null !== $topics ? (array) $topics : null; } @@ -61,6 +62,11 @@ public function getRetry(): ?int return $this->retry; } + public function getContent(): ?array + { + return $this->content; + } + public function toArray(): array { return [ @@ -69,6 +75,7 @@ public function toArray(): array 'id' => $this->id, 'type' => $this->type, 'retry' => $this->retry, + 'content' => $this->content, ]; } diff --git a/src/Symfony/Component/Notifier/Bridge/Mercure/MercureTransport.php b/src/Symfony/Component/Notifier/Bridge/Mercure/MercureTransport.php index 1be37a534ff88..cfdaed50964c2 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mercure/MercureTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Mercure/MercureTransport.php @@ -77,6 +77,8 @@ protected function doSend(MessageInterface $message): SentMessage '@context' => 'https://www.w3.org/ns/activitystreams', 'type' => 'Announce', 'summary' => $message->getSubject(), + 'mediaType' => 'application/json', + 'content' => $options->getContent(), ]), $options->isPrivate(), $options->getId(), $options->getType(), $options->getRetry()); try { diff --git a/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureOptionsTest.php b/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureOptionsTest.php index 7503f9e40456f..aa5d3ce8f024c 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureOptionsTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureOptionsTest.php @@ -24,12 +24,13 @@ public function testConstructWithDefaults() 'id' => null, 'type' => null, 'retry' => null, + 'content' => null, ]); } public function testConstructWithParameters() { - $options = (new MercureOptions('/topic/1', true, 'id', 'type', 1)); + $options = (new MercureOptions('/topic/1', true, 'id', 'type', 1, ['tag' => '1234', 'body' => 'TEST'])); $this->assertSame($options->toArray(), [ 'topics' => ['/topic/1'], @@ -37,6 +38,7 @@ public function testConstructWithParameters() 'id' => 'id', 'type' => 'type', 'retry' => 1, + 'content' => ['tag' => '1234', 'body' => 'TEST'], ]); } diff --git a/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureTransportTest.php index bfe9190a8e592..40b07f1ffc58b 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Mercure/Tests/MercureTransportTest.php @@ -114,7 +114,7 @@ public function testSendWithMercureOptions() { $hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo'), function (Update $update): string { $this->assertSame(['/topic/1', '/topic/2'], $update->getTopics()); - $this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject"}', $update->getData()); + $this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject","mediaType":"application\/json","content":{"tag":"1234","body":"TEST"}}', $update->getData()); $this->assertSame('id', $update->getId()); $this->assertSame('type', $update->getType()); $this->assertSame(1, $update->getRetry()); @@ -123,14 +123,14 @@ public function testSendWithMercureOptions() return 'id'; }); - self::createTransport(null, $hub)->send(new ChatMessage('subject', new MercureOptions(['/topic/1', '/topic/2'], true, 'id', 'type', 1))); + self::createTransport(null, $hub)->send(new ChatMessage('subject', new MercureOptions(['/topic/1', '/topic/2'], true, 'id', 'type', 1, ['tag' => '1234', 'body' => 'TEST']))); } public function testSendWithMercureOptionsButWithoutOptionTopic() { $hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo'), function (Update $update): string { $this->assertSame(['https://symfony.com/notifier'], $update->getTopics()); - $this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject"}', $update->getData()); + $this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject","mediaType":"application\/json","content":null}', $update->getData()); $this->assertSame('id', $update->getId()); $this->assertSame('type', $update->getType()); $this->assertSame(1, $update->getRetry()); @@ -146,7 +146,7 @@ public function testSendWithoutMercureOptions() { $hub = new MockHub('https://foo.com/.well-known/mercure', new StaticTokenProvider('foo'), function (Update $update): string { $this->assertSame(['https://symfony.com/notifier'], $update->getTopics()); - $this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject"}', $update->getData()); + $this->assertSame('{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","type":"Announce","summary":"subject","mediaType":"application\/json","content":null}', $update->getData()); $this->assertFalse($update->isPrivate()); return 'id';