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

Skip to content

[Notifier] Introduce NullMessage and remove transport setter in MessageInterface #38474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Message/ChatMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getOptions(): ?MessageOptionsInterface
/**
* @return $this
*/
public function transport(?string $transport): MessageInterface
public function transport(?string $transport): self
{
$this->transport = $transport;

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Message/EmailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getOptions(): ?MessageOptionsInterface
/**
* @return $this
*/
public function transport(string $transport): MessageInterface
public function transport(string $transport): self
{
if (!$this->message instanceof Email) {
throw new LogicException('Cannot set a Transport on a RawMessage instance.');
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Notifier/Message/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ public function getSubject(): string;
public function getOptions(): ?MessageOptionsInterface;

public function getTransport(): ?string;

public function transport(string $transport): self;
}
47 changes: 47 additions & 0 deletions src/Symfony/Component/Notifier/Message/NullMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Message;

/**
* @author Jan Schädlich <[email protected]>
*
* @experimental in 5.2
*/
final class NullMessage implements MessageInterface
{
private $decoratedMessage;

public function __construct(MessageInterface $message)
{
$this->decoratedMessage = $message;
}

public function getRecipientId(): ?string
{
return $this->decoratedMessage->getRecipientId();
}

public function getSubject(): string
{
return $this->decoratedMessage->getSubject();
}

public function getOptions(): ?MessageOptionsInterface
{
return $this->decoratedMessage->getOptions();
}

public function getTransport(): ?string
{
return $this->decoratedMessage->getTransport() ?? 'null';
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Message/SmsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getSubject(): string
/**
* @return $this
*/
public function transport(string $transport): MessageInterface
public function transport(string $transport): self
{
$this->transport = $transport;

Expand Down
5 changes: 2 additions & 3 deletions src/Symfony/Component/Notifier/Transport/NullTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Notifier\Event\MessageEvent;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\NullMessage;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

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

public function send(MessageInterface $message): SentMessage
{
if (null === $message->getTransport()) {
$message->transport((string) $this);
}
$message = new NullMessage($message);

if (null !== $this->dispatcher) {
$this->dispatcher->dispatch(new MessageEvent($message));
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Notifier/Transport/Transports.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public function send(MessageInterface $message): SentMessage
if (!$transport = $message->getTransport()) {
foreach ($this->transports as $transportName => $transport) {
if ($transport->supports($message)) {
$message->transport($transportName);

return $transport->send($message);
}
}
Expand Down