@@ -338,7 +338,7 @@ To send a notification, autowire the
338
338
339
339
use Symfony\Component\Notifier\Notification\Notification;
340
340
use Symfony\Component\Notifier\NotifierInterface;
341
- use Symfony\Component\Notifier\Recipient\AdminRecipient ;
341
+ use Symfony\Component\Notifier\Recipient\Recipient ;
342
342
343
343
class InvoiceController extends AbstractController
344
344
{
@@ -355,7 +355,7 @@ To send a notification, autowire the
355
355
->content('You got a new invoice for 15 EUR.');
356
356
357
357
// The receiver of the Notification
358
- $recipient = new AdminRecipient (
358
+ $recipient = new Recipient (
359
359
$user->getEmail(),
360
360
$user->getPhonenumber()
361
361
);
@@ -375,22 +375,23 @@ both an email and sms notification to the user.
375
375
The default notification also has a ``content() `` and ``emoji() `` method to
376
376
set the notification content and icon.
377
377
378
- Symfony provides three types of recipients:
378
+ Symfony provides the following recipients:
379
379
380
380
:class: `Symfony\\ Component\\ Notifier\\ Recipient\\ NoRecipient `
381
381
This is the default and is useful when there is no need to have
382
382
information about the receiver. For example, the browser channel uses
383
383
the current requests's :ref: `session flashbag <flash-messages >`;
384
384
385
385
:class: `Symfony\\ Component\\ Notifier\\ Recipient\\ Recipient `
386
- This contains only the email address of the user and can be used for
387
- messages on the email and browser channel;
388
-
389
- :class: `Symfony\\ Component\\ Notifier\\ Recipient\\ AdminRecipient `
390
386
This can contain both email address and phonenumber of the user. This
391
387
recipient can be used for all channels (depending on whether they are
392
388
actually set).
393
389
390
+ .. versionadded :: 5.2
391
+
392
+ The ``AdminRecipient `` class was removed in Symfony 5.2, you should use
393
+ ``Recipient `` instead.
394
+
394
395
Configuring Channel Policies
395
396
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
396
397
@@ -505,7 +506,8 @@ very high and the recipient has a phone number::
505
506
namespace App\Notifier;
506
507
507
508
use Symfony\Component\Notifier\Notification\Notification;
508
- use Symfony\Component\Notifier\Recipient\Recipient;
509
+ use Symfony\Component\Notifier\Recipient\RecipientInterface;
510
+ use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
509
511
510
512
class InvoiceNotification extends Notification
511
513
{
@@ -516,12 +518,11 @@ very high and the recipient has a phone number::
516
518
$this->price = $price;
517
519
}
518
520
519
- public function getChannels(Recipient $recipient)
521
+ public function getChannels(RecipientInterface $recipient)
520
522
{
521
523
if (
522
524
$this->price > 10000
523
- && $recipient instanceof AdminRecipient
524
- && null !== $recipient->getPhone()
525
+ && $recipient instanceof SmsRecipientInterface
525
526
) {
526
527
return ['sms'];
527
528
}
@@ -545,7 +546,7 @@ and its ``asChatMessage()`` method::
545
546
use Symfony\Component\Notifier\Message\ChatMessage;
546
547
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
547
548
use Symfony\Component\Notifier\Notification\Notification;
548
- use Symfony\Component\Notifier\Recipient\Recipient ;
549
+ use Symfony\Component\Notifier\Recipient\SmsRecipientInterface ;
549
550
550
551
class InvoiceNotification extends Notification implements ChatNotificationInterface
551
552
{
@@ -556,7 +557,7 @@ and its ``asChatMessage()`` method::
556
557
$this->price = $price;
557
558
}
558
559
559
- public function asChatMessage(Recipient $recipient, string $transport = null): ?ChatMessage
560
+ public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
560
561
{
561
562
// Add a custom emoji if the message is sent to Slack
562
563
if ('slack' === $transport) {
0 commit comments