Skip to content

Commit 1b88b8b

Browse files
committed
feature symfony#38361 Can define ChatMessage transport to null (odolbeau)
This PR was submitted for the 5.1 branch but it was merged into the 5.2-dev branch instead. Discussion ---------- Can define ChatMessage transport to null | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT I'm using notiier & messenger together to send notification asynchronously. In order to have json messages in my broker, here is the messenger config I use: ```yaml serializer: default_serializer: messenger.transport.symfony_serializer symfony_serializer: format: json context: { } ``` I send a new `ChatMessage`: ```php use Symfony\Component\Notifier\ChatterInterface; use Symfony\Component\Notifier\Message\ChatMessage; $chatter->send(new ChatMessage('Using notifier & messenger together is amazing!'); ``` Message is correctly sent to my broker, in json: ```json { "subject": "Using notifier & messenger together is amazing!", "recipientId": null, "options": null, "transport": null, "notification": null } ``` But when I want to consume it, as the `transport` method used by the serializer to create the `ChatMessage` doesn't accept `null` value, I get the following error: ``` [Symfony\Component\Messenger\Exception\MessageDecodingFailedException] Could not decode message: Failed to denormalize attribute "transport" value for class "Symfony\Component\Notifier\Message\ChatMessage": Expected argument of type "string", "null" given at property path "transport". ``` This PR correct the problem, even if I'm not sure it's the best way to go... Commits ------- 09c9bde Can define ChatMessage transport to null
2 parents b35bbdb + 09c9bde commit 1b88b8b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Symfony/Component/Notifier/Message/ChatMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getOptions(): ?MessageOptionsInterface
7777
/**
7878
* @return $this
7979
*/
80-
public function transport(string $transport): self
80+
public function transport(?string $transport): self
8181
{
8282
$this->transport = $transport;
8383

0 commit comments

Comments
 (0)