@@ -348,7 +348,7 @@ To send a notification, autowire the
348
348
349
349
use Symfony\Component\Notifier\Notification\Notification;
350
350
use Symfony\Component\Notifier\NotifierInterface;
351
- use Symfony\Component\Notifier\Recipient\AdminRecipient ;
351
+ use Symfony\Component\Notifier\Recipient\Recipient ;
352
352
353
353
class InvoiceController extends AbstractController
354
354
{
@@ -365,7 +365,7 @@ To send a notification, autowire the
365
365
->content('You got a new invoice for 15 EUR.');
366
366
367
367
// The receiver of the Notification
368
- $recipient = new AdminRecipient (
368
+ $recipient = new Recipient (
369
369
$user->getEmail(),
370
370
$user->getPhonenumber()
371
371
);
@@ -385,22 +385,23 @@ both an email and sms notification to the user.
385
385
The default notification also has a ``content() `` and ``emoji() `` method to
386
386
set the notification content and icon.
387
387
388
- Symfony provides three types of recipients:
388
+ Symfony provides the following recipients:
389
389
390
390
:class: `Symfony\\ Component\\ Notifier\\ Recipient\\ NoRecipient `
391
391
This is the default and is useful when there is no need to have
392
392
information about the receiver. For example, the browser channel uses
393
393
the current requests's :ref: `session flashbag <flash-messages >`;
394
394
395
395
:class: `Symfony\\ Component\\ Notifier\\ Recipient\\ Recipient `
396
- This contains only the email address of the user and can be used for
397
- messages on the email and browser channel;
398
-
399
- :class: `Symfony\\ Component\\ Notifier\\ Recipient\\ AdminRecipient `
400
396
This can contain both email address and phonenumber of the user. This
401
397
recipient can be used for all channels (depending on whether they are
402
398
actually set).
403
399
400
+ .. versionadded :: 5.2
401
+
402
+ The ``AdminRecipient `` class was removed in Symfony 5.2, you should use
403
+ ``Recipient `` instead.
404
+
404
405
Configuring Channel Policies
405
406
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406
407
@@ -515,7 +516,8 @@ very high and the recipient has a phone number::
515
516
namespace App\Notifier;
516
517
517
518
use Symfony\Component\Notifier\Notification\Notification;
518
- use Symfony\Component\Notifier\Recipient\Recipient;
519
+ use Symfony\Component\Notifier\Recipient\RecipientInterface;
520
+ use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
519
521
520
522
class InvoiceNotification extends Notification
521
523
{
@@ -526,12 +528,11 @@ very high and the recipient has a phone number::
526
528
$this->price = $price;
527
529
}
528
530
529
- public function getChannels(Recipient $recipient)
531
+ public function getChannels(RecipientInterface $recipient)
530
532
{
531
533
if (
532
534
$this->price > 10000
533
- && $recipient instanceof AdminRecipient
534
- && null !== $recipient->getPhone()
535
+ && $recipient instanceof SmsRecipientInterface
535
536
) {
536
537
return ['sms'];
537
538
}
@@ -555,7 +556,7 @@ and its ``asChatMessage()`` method::
555
556
use Symfony\Component\Notifier\Message\ChatMessage;
556
557
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
557
558
use Symfony\Component\Notifier\Notification\Notification;
558
- use Symfony\Component\Notifier\Recipient\Recipient ;
559
+ use Symfony\Component\Notifier\Recipient\SmsRecipientInterface ;
559
560
560
561
class InvoiceNotification extends Notification implements ChatNotificationInterface
561
562
{
@@ -566,7 +567,7 @@ and its ``asChatMessage()`` method::
566
567
$this->price = $price;
567
568
}
568
569
569
- public function asChatMessage(Recipient $recipient, string $transport = null): ?ChatMessage
570
+ public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
570
571
{
571
572
// Add a custom emoji if the message is sent to Slack
572
573
if ('slack' === $transport) {
0 commit comments