Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0137609

Browse files
committed
minor #38474 [Notifier] Introduce NullMessage and remove transport setter in MessageInterface (jschaedl)
This PR was merged into the 5.x branch. Discussion ---------- [Notifier] Introduce NullMessage and remove transport setter in MessageInterface | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | - <!-- required for new features --> Follow-up PR of #36479 Commits ------- 5701e89 Introduce NullMessage and remove transport setter in MessageInterface
2 parents a6b6dbb + 5701e89 commit 0137609

File tree

7 files changed

+52
-10
lines changed

7 files changed

+52
-10
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): MessageInterface
80+
public function transport(?string $transport): self
8181
{
8282
$this->transport = $transport;
8383

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function getOptions(): ?MessageOptionsInterface
102102
/**
103103
* @return $this
104104
*/
105-
public function transport(string $transport): MessageInterface
105+
public function transport(string $transport): self
106106
{
107107
if (!$this->message instanceof Email) {
108108
throw new LogicException('Cannot set a Transport on a RawMessage instance.');

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ public function getSubject(): string;
2525
public function getOptions(): ?MessageOptionsInterface;
2626

2727
public function getTransport(): ?string;
28-
29-
public function transport(string $transport): self;
3028
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Message;
13+
14+
/**
15+
* @author Jan Schädlich <[email protected]>
16+
*
17+
* @experimental in 5.2
18+
*/
19+
final class NullMessage implements MessageInterface
20+
{
21+
private $decoratedMessage;
22+
23+
public function __construct(MessageInterface $message)
24+
{
25+
$this->decoratedMessage = $message;
26+
}
27+
28+
public function getRecipientId(): ?string
29+
{
30+
return $this->decoratedMessage->getRecipientId();
31+
}
32+
33+
public function getSubject(): string
34+
{
35+
return $this->decoratedMessage->getSubject();
36+
}
37+
38+
public function getOptions(): ?MessageOptionsInterface
39+
{
40+
return $this->decoratedMessage->getOptions();
41+
}
42+
43+
public function getTransport(): ?string
44+
{
45+
return $this->decoratedMessage->getTransport() ?? 'null';
46+
}
47+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getSubject(): string
8383
/**
8484
* @return $this
8585
*/
86-
public function transport(string $transport): MessageInterface
86+
public function transport(string $transport): self
8787
{
8888
$this->transport = $transport;
8989

src/Symfony/Component/Notifier/Transport/NullTransport.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
1616
use Symfony\Component\Notifier\Event\MessageEvent;
1717
use Symfony\Component\Notifier\Message\MessageInterface;
18+
use Symfony\Component\Notifier\Message\NullMessage;
1819
use Symfony\Component\Notifier\Message\SentMessage;
1920
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2021

@@ -34,9 +35,7 @@ public function __construct(EventDispatcherInterface $dispatcher = null)
3435

3536
public function send(MessageInterface $message): SentMessage
3637
{
37-
if (null === $message->getTransport()) {
38-
$message->transport((string) $this);
39-
}
38+
$message = new NullMessage($message);
4039

4140
if (null !== $this->dispatcher) {
4241
$this->dispatcher->dispatch(new MessageEvent($message));

src/Symfony/Component/Notifier/Transport/Transports.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function send(MessageInterface $message): SentMessage
5757
if (!$transport = $message->getTransport()) {
5858
foreach ($this->transports as $transportName => $transport) {
5959
if ($transport->supports($message)) {
60-
$message->transport($transportName);
61-
6260
return $transport->send($message);
6361
}
6462
}

0 commit comments

Comments
 (0)