8000 [Notifier] Introduce FromNotificationInterface for MessageInterface implementations by fabpot · Pull Request #49327 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier] Introduce FromNotificationInterface for MessageInterface implementations #49327

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 10, 2023
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
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/CHANGELOG.md
8000
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.3
---

* Introduce `FromNotificationInterface` for `MessageInterface` implementations

6.2
---

Expand Down
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 @@ -16,7 +16,7 @@
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class ChatMessage implements MessageInterface
class ChatMessage implements MessageInterface, FromNotificationInterface
{
private ?string $transport = null;
private string $subject;
Expand Down
13 changes: 11 additions & 2 deletions src/Symfony/Component/Notifier/Message/EmailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class EmailMessage implements MessageInterface
class EmailMessage implements MessageInterface, FromNotificationInterface
{
private RawMessage $message;
private ?Envelope $envelope;
private ?Notification $notification = null;

public function __construct(RawMessage $message, Envelope $envelope = null)
{
Expand Down Expand Up @@ -59,7 +60,10 @@ public static function fromNotification(Notification $notification, EmailRecipie
}
}

return new self($email);
$message = new self($email);
$message->notification = $notification;

return $message;
}

public function getMessage(): RawMessage
Expand Down Expand Up @@ -118,4 +122,9 @@ public function getTransport(): ?string
{
return $this->message instanceof Email ? $this->message->getHeaders()->getHeaderBody('X-Transport') : null;
}

public function getNotification(): ?Notification
{
return $this->notification;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

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

namespace Symfony\Component\Notifier\Message;

use Symfony\Component\Notifier\Notification\Notification;

/**
* @author Fabien Potencier <fabien@symfony.com>
*/
interface FromNotificationInterface
{
public function getNotification(): ?Notification;
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Message/PushMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
*/
class PushMessage implements MessageInterface
class PushMessage implements MessageInterface, FromNotificationInterface
{
private $transport;
private $subject;
Expand Down
13 changes: 11 additions & 2 deletions src/Symfony/Component/Notifier/Message/SmsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class SmsMessage implements MessageInterface
class SmsMessage implements MessageInterface, FromNotificationInterface
{
private ?string $transport = null;
private string $subject;
private string $phone;
private string $from;
private ?MessageOptionsInterface $options;
private ?Notification $notification = null;

public function __construct(string $phone, string $subject, string $from = '', MessageOptionsInterface $options = null)
{
Expand All @@ -40,7 +41,10 @@ public function __construct(string $phone, string $subject, string $from = '', M

public static function fromNotification(Notification $notification, SmsRecipientInterface $recipient): self
{
return new self($recipient->getPhone(), $notification->getSubject());
$message = new self($recipient->getPhone(), $notification->getSubject());
$message->notification = $notification;

return $message;
}

/**
Expand Down Expand Up @@ -126,4 +130,9 @@ public function getOptions(): ?MessageOptionsInterface
{
return $this->options;
}

public function getNotification(): ?Notification
{
return $this->notification;
}
}
0