Skip to content

Commit 588607b

Browse files
jschaedlfabpot
authored andcommitted
[Notifier] Change notifier recipient handling
1 parent e1cfbd2 commit 588607b

28 files changed

+330
-111
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
107107
use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
108108
use Symfony\Component\Notifier\Notifier;
109-
use Symfony\Component\Notifier\Recipient\AdminRecipient;
109+
use Symfony\Component\Notifier\Recipient\Recipient;
110110
use Symfony\Component\PropertyAccess\PropertyAccessor;
111111
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
112112
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
@@ -2096,7 +2096,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
20962096
$notifier = $container->getDefinition('notifier');
20972097
foreach ($config['admin_recipients'] as $i => $recipient) {
20982098
$id = 'notifier.admin_recipient.'.$i;
2099-
$container->setDefinition($id, new Definition(AdminRecipient::class, [$recipient['email'], $recipient['phone']]));
2099+
$container->setDefinition($id, new Definition(Recipient::class, [$recipient['email'], $recipient['phone']]));
21002100
$notifier->addMethodCall('addAdminRecipient', [new Reference($id)]);
21012101
}
21022102
}

src/Symfony/Component/Notifier/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ CHANGELOG
66

77
* [BC BREAK] The `TransportInterface::send()` and `AbstractTransport::doSend()` methods changed to return a `?SentMessage` instance instead of `void`.
88
* Added the Zulip notifier bridge
9+
* The `EmailRecipientInterface` and `RecipientInterface` were introduced.
10+
* Added `email` and and `phone` properties to `Recipient`.
11+
* [BC BREAK] Changed the type-hint of the `$recipient` argument in the `as*Message()`
12+
of the `EmailNotificationInterface` and `SmsNotificationInterface` to `EmailRecipientInterface`
13+
and `SmsRecipientInterface`.
14+
* [BC BREAK] Removed the `AdminRecipient`.
15+
* The `EmailRecipientInterface` and `SmsRecipientInterface` now extend the `RecipientInterface`.
16+
* The `EmailRecipient` and `SmsRecipient` were introduced.
17+
* [BC BREAK] Changed the type-hint of the `$recipient` argument in `NotifierInterface::send()`,
18+
`Notifier::getChannels()`, `ChannelInterface::notifiy()` and `ChannelInterface::supports()` to
19+
`RecipientInterface`.
20+
* Changed `EmailChannel` to only support recipients which implement the `EmailRecipientInterface`.
21+
* Changed `SmsChannel` to only support recipients which implement the `SmsRecipientInterface`.
22+
923

1024
5.1.0
1125
-----

src/Symfony/Component/Notifier/Channel/BrowserChannel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\RequestStack;
1515
use Symfony\Component\Notifier\Notification\Notification;
16-
use Symfony\Component\Notifier\Recipient\Recipient;
16+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
1717

1818
/**
1919
* @author Fabien Potencier <fabien@symfony.com>
@@ -29,7 +29,7 @@ public function __construct(RequestStack $stack)
2929
$this->stack = $stack;
3030
}
3131

32-
public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
32+
public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
3333
{
3434
if (null === $request = $this->stack->getCurrentRequest()) {
3535
return;
@@ -42,7 +42,7 @@ public function notify(Notification $notification, Recipient $recipient, string
4242
$request->getSession()->getFlashBag()->add('notification', $message);
4343
}
4444

45-
public function supports(Notification $notification, Recipient $recipient): bool
45+
public function supports(Notification $notification, RecipientInterface $recipient): bool
4646
{
4747
return true;
4848
}

src/Symfony/Component/Notifier/Channel/ChannelInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Notifier\Channel;
1313

1414
use Symfony\Component\Notifier\Notification\Notification;
15-
use Symfony\Component\Notifier\Recipient\Recipient;
15+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
1616

1717
/**
1818
* @author Fabien Potencier <fabien@symfony.com>
@@ -21,7 +21,7 @@
2121
*/
2222
interface ChannelInterface
2323
{
24-
public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void;
24+
public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void;
2525

26-
public function supports(Notification $notification, Recipient $recipient): bool;
26+
public function supports(Notification $notification, RecipientInterface $recipient): bool;
2727
}

src/Symfony/Component/Notifier/Channel/ChatChannel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Notifier\Message\ChatMessage;
1515
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
1616
use Symfony\Component\Notifier\Notification\Notification;
17-
use Symfony\Component\Notifier\Recipient\Recipient;
17+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
1818

1919
/**
2020
* @author Fabien Potencier <fabien@symfony.com>
@@ -23,7 +23,7 @@
2323
*/
2424
class ChatChannel extends AbstractChannel
2525
{
26-
public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
26+
public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
2727
{
2828
$message = null;
2929
if ($notification instanceof ChatNotificationInterface) {
@@ -45,7 +45,7 @@ public function notify(Notification $notification, Recipient $recipient, string
4545
}
4646
}
4747

48-
public function supports(Notification $notification, Recipient $recipient): bool
48+
public function supports(Notification $notification, RecipientInterface $recipient): bool
4949
{
5050
return true;
5151
}

src/Symfony/Component/Notifier/Channel/EmailChannel.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
use Symfony\Component\Notifier\Message\EmailMessage;
2121
use Symfony\Component\Notifier\Notification\EmailNotificationInterface;
2222
use Symfony\Component\Notifier\Notification\Notification;
23-
use Symfony\Component\Notifier\Recipient\Recipient;
23+
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
24+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
2425

2526
/**
2627
* @author Fabien Potencier <fabien@symfony.com>
@@ -46,7 +47,7 @@ public function __construct(TransportInterface $transport = null, MessageBusInte
4647
$this->envelope = $envelope;
4748
}
4849

49-
public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
50+
public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
5051
{
5152
$message = null;
5253
if ($notification instanceof EmailNotificationInterface) {
@@ -84,8 +85,8 @@ public function notify(Notification $notification, Recipient $recipient, string
8485
}
8586
}
8687

87-
public function supports(Notification $notification, Recipient $recipient): bool
88+
public function supports(Notification $notification, RecipientInterface $recipient): bool
8889
{
89-
return '' !== $recipient->getEmail();
90+
return $recipient instanceof EmailRecipientInterface;
9091
}
9192
}

src/Symfony/Component/Notifier/Channel/SmsChannel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Notifier\Message\SmsMessage;
1515
use Symfony\Component\Notifier\Notification\Notification;
1616
use Symfony\Component\Notifier\Notification\SmsNotificationInterface;
17-
use Symfony\Component\Notifier\Recipient\Recipient;
17+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
1818
use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
1919

2020
/**
@@ -24,7 +24,7 @@
2424
*/
2525
class SmsChannel extends AbstractChannel
2626
{
27-
public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
27+
public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
2828
{
2929
$message = null;
3030
if ($notification instanceof SmsNotificationInterface) {
@@ -46,8 +46,8 @@ public function notify(Notification $notification, Recipient $recipient, string
4646
}
4747
}
4848

49-
public function supports(Notification $notification, Recipient $recipient): bool
49+
public function supports(Notification $notification, RecipientInterface $recipient): bool
5050
{
51-
return $recipient instanceof SmsRecipientInterface && '' !== $recipient->getPhone();
51+
return $recipient instanceof SmsRecipientInterface;
5252
}
5353
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
use Symfony\Component\Mailer\Envelope;
1616
use Symfony\Component\Mime\Email;
1717
use Symfony\Component\Mime\RawMessage;
18+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1819
use Symfony\Component\Notifier\Exception\LogicException;
1920
use Symfony\Component\Notifier\Notification\Notification;
20-
use Symfony\Component\Notifier\Recipient\Recipient;
21+
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
2122

2223
/**
2324
* @author Fabien Potencier <fabien@symfony.com>
@@ -35,8 +36,12 @@ public function __construct(RawMessage $message, Envelope $envelope = null)
3536
$this->envelope = $envelope;
3637
}
3738

38-
public static function fromNotification(Notification $notification, Recipient $recipient): self
39+
public static function fromNotification(Notification $notification, EmailRecipientInterface $recipient): self
3940
{
41+
if ('' === $recipient->getEmail()) {
42+
throw new InvalidArgumentException(sprintf('"%s" needs an email, it cannot be empty.', static::class));
43+
}
44+
4045
if (!class_exists(NotificationEmail::class)) {
4146
$email = (new Email())
4247
->to($recipient->getEmail())

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
namespace Symfony\Component\Notifier\Message;
1313

14-
use Symfony\Component\Notifier\Exception\LogicException;
14+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1515
use Symfony\Component\Notifier\Notification\Notification;
16-
use Symfony\Component\Notifier\Notification\SmsNotificationInterface;
17-
use Symfony\Component\Notifier\Recipient\Recipient;
1816
use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
1917

2018
/**
@@ -30,16 +28,16 @@ final class SmsMessage implements MessageInterface
3028

3129
public function __construct(string $phone, string $subject)
3230
{
31+
if ('' === $phone) {
32+
throw new InvalidArgumentException(sprintf('"%s" needs a phone number, it cannot be empty.', static::class));
33+
}
34+
3335
$this->subject = $subject;
3436
$this->phone = $phone;
3537
}
3638

37-
public static function fromNotification(Notification $notification, Recipient $recipient): self
39+
public static function fromNotification(Notification $notification, SmsRecipientInterface $recipient): self
3840
{
39-
if (!$recipient instanceof SmsRecipientInterface) {
40-
throw new LogicException(sprintf('To send a SMS message, "%s" should implement "%s" or the recipient should implement "%s".', get_debug_type($notification), SmsNotificationInterface::class, SmsRecipientInterface::class));
41-
}
42-
4341
return new self($recipient->getPhone(), $notification->getSubject());
4442
}
4543

@@ -48,6 +46,10 @@ public static function fromNotification(Notification $notification, Recipient $r
4846
*/
4947
public function phone(string $phone): self
5048
{
49+
if ('' === $phone) {
50+
throw new InvalidArgumentException(sprintf('"%s" needs a phone number, it cannot be empty.', static::class));
51+
}
52+
5153
$this->phone = $phone;
5254

5355
return $this;

src/Symfony/Component/Notifier/Notification/ChatNotificationInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Notifier\Notification;
1313

1414
use Symfony\Component\Notifier\Message\ChatMessage;
15-
use Symfony\Component\Notifier\Recipient\Recipient;
15+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
1616

1717
/**
1818
* @author Fabien Potencier <fabien@symfony.com>
@@ -21,5 +21,5 @@
2121
*/
2222
interface ChatNotificationInterface
2323
{
24-
public function asChatMessage(Recipient $recipient, string $transport = null): ?ChatMessage;
24+
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage;
2525
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy