diff --git a/src/Symfony/Component/Notifier/Bridge/Mercure/CHANGELOG.md b/src/Symfony/Component/Notifier/Bridge/Mercure/CHANGELOG.md index 1f2b652ac20ea..29eb84188aded 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 da3b2e8797b34..cd55a68efde71 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mercure/MercureOptions.php +++ b/src/Symfony/Component/Notifier/Bridge/Mercure/MercureOptions.php @@ -23,17 +23,19 @@ final class MercureOptions implements MessageOptionsInterface private ?string $id; private ?string $type; private ?int $retry; + private ?array $content; /** * @param string|string[]|null $topics */ - public function __construct(string|array|null $topics = null, bool $private = false, ?string $id = null, ?string $type = null, ?int $retry = null) + public function __construct(string|array|null $topics = null, bool $private = false, ?string $id = null, ?string $type = null, ?int $retry = null, ?array $content = null) { $this->topics = null !== $topics ? (array) $topics : null; $this->private = $private; $this->id = $id; $this->type = $type; $this->retry = $retry; + $this->content = $content; } /** @@ -64,6 +66,11 @@ public function getRetry(): ?int return $this->retry; } + public function getContent(): ?array + { + return $this->content; + } + public function toArray(): array { return [ @@ -72,6 +79,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 72559b85fa85f..355af24982fff 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..d3a7ed8aa6a95 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..6e7c391b7278d 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":null}', $update->getData()); $this->assertSame('id', $update->getId()); $this->assertSame('type', $update->getType()); $this->assertSame(1, $update->getRetry()); @@ -130,7 +130,7 @@ 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';