Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Notifier] Remove superfluous parameters in *Message::fromNotification() #35167

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
Feb 4, 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
8 changes: 8 additions & 0 deletions 8 UPGRADE-5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ HttpFoundation
`RedirectResponse::create()`, and `StreamedResponse::create()` methods (use
`__construct()` instead)

Notifier
--------

* [BC BREAK] The `ChatMessage::fromNotification()` method's `$recipient` and `$transport`
arguments were removed.
* [BC BREAK] The `EmailMessage::fromNotification()` and `SmsMessage::fromNotification()`
methods' `$transport` argument was removed.

Routing
-------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\Recipient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

Expand Down Expand Up @@ -145,7 +144,7 @@ public function testSendWithNotification(): void
->willReturn(json_encode(['ok' => true]));

$notification = new Notification($message);
$chatMessage = ChatMessage::fromNotification($notification, new Recipient('test-email@example.com'));
$chatMessage = ChatMessage::fromNotification($notification);
$options = SlackOptions::fromNotification($notification);

$expectedBody = http_build_query([
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Notifier/Bridge/Slack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "^7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.0"
"symfony/notifier": "^5.1"
},
"require-dev": {
"symfony/event-dispatcher": "^4.3|^5.0"
Expand Down
8 changes: 8 additions & 0 deletions 8 src/Symfony/Component/Notifier/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

5.1.0
-----

* [BC BREAK] The `ChatMessage::fromNotification()` method's `$recipient` and `$transport`
arguments were removed.
* [BC BREAK] The `EmailMessage::fromNotification()` and `SmsMessage::fromNotification()`
methods' `$transport` argument was removed.

5.0.0
-----

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Notifier/Channel/ChatChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function notify(Notification $notification, Recipient $recipient, string
}

if (null === $message) {
$message = ChatMessage::fromNotification($notification, $recipient, $transportName);
$message = ChatMessage::fromNotification($notification);
}

$message->transport($transportName);
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Notifier/Channel/SmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function notify(Notification $notification, Recipient $recipient, string
}

if (null === $message) {
$message = SmsMessage::fromNotification($notification, $recipient, $transportName);
$message = SmsMessage::fromNotification($notification, $recipient);
}

if (null !== $transportName) {
Expand Down
3 changes: 1 addition & 2 deletions 3 src/Symfony/Component/Notifier/Message/ChatMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Notifier\Message;

use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\Recipient;

/**
* @author Fabien Potencier <fabien@symfony.com>
Expand All @@ -32,7 +31,7 @@ public function __construct(string $subject, MessageOptionsInterface $options =
$this->options = $options;
}

public static function fromNotification(Notification $notification, Recipient $recipient, string $transport = null): self
public static function fromNotification(Notification $notification): self
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need $recipient here in the future? But being forced to pass an useless argument is worse in practice for me.

{
$message = new self($notification->getSubject());
$message->notification = $notification;
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Notifier/Message/EmailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(RawMessage $message, Envelope $envelope = null)
$this->envelope = $envelope;
}

public static function fromNotification(Notification $notification, Recipient $recipient, string $transport = null): self
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative: for the $transport, we could set the transport directly from this method then? But the current code uses the setter everytime.

public static function fromNotification(Notification $notification, Recipient $recipient): self
{
if (!class_exists(NotificationEmail::class)) {
$email = (new Email())
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Notifier/Message/SmsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public function __construct(string $phone, string $subject)
$this->phone = $phone;
}

public static function fromNotification(Notification $notification, Recipient $recipient, string $transport = null): self
public static function fromNotification(Notification $notification, Recipient $recipient): self
{
if (!$recipient instanceof SmsRecipientInterface) {
throw new LogicException(sprintf('To send a SMS message, "%s" should implement "%s" or the recipient should implement "%s".', get_class($notification), SmsNotificationInterface::class, SmsRecipientInterface::class));
throw new LogicException(sprintf('To send a SMS message, "%s" should implement "%s" or the recipient should implement "%s".', \get_class($notification), SmsNotificationInterface::class, SmsRecipientInterface::class));
}

return new self($recipient->getPhone(), $notification->getSubject());
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.