Skip to content

Commit bc29b4c

Browse files
jschaedlxabbuh
authored andcommitted
[Notifier] Adjust notifier documentation
1 parent 52c2ca0 commit bc29b4c

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

notifier.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ To send a notification, autowire the
338338

339339
use Symfony\Component\Notifier\Notification\Notification;
340340
use Symfony\Component\Notifier\NotifierInterface;
341-
use Symfony\Component\Notifier\Recipient\AdminRecipient;
341+
use Symfony\Component\Notifier\Recipient\Recipient;
342342

343343
class InvoiceController extends AbstractController
344344
{
@@ -355,7 +355,7 @@ To send a notification, autowire the
355355
->content('You got a new invoice for 15 EUR.');
356356

357357
// The receiver of the Notification
358-
$recipient = new AdminRecipient(
358+
$recipient = new Recipient(
359359
$user->getEmail(),
360360
$user->getPhonenumber()
361361
);
@@ -375,22 +375,23 @@ both an email and sms notification to the user.
375375
The default notification also has a ``content()`` and ``emoji()`` method to
376376
set the notification content and icon.
377377

378-
Symfony provides three types of recipients:
378+
Symfony provides the following recipients:
379379

380380
:class:`Symfony\\Component\\Notifier\\Recipient\\NoRecipient`
381381
This is the default and is useful when there is no need to have
382382
information about the receiver. For example, the browser channel uses
383383
the current requests's :ref:`session flashbag <flash-messages>`;
384384

385385
: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`
390386
This can contain both email address and phonenumber of the user. This
391387
recipient can be used for all channels (depending on whether they are
392388
actually set).
393389

390+
.. versionadded:: 5.2
391+
392+
The ``AdminRecipient`` class was removed in Symfony 5.2, you should use
393+
``Recipient`` instead.
394+
394395
Configuring Channel Policies
395396
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
396397

@@ -505,7 +506,8 @@ very high and the recipient has a phone number::
505506
namespace App\Notifier;
506507

507508
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;
509511

510512
class InvoiceNotification extends Notification
511513
{
@@ -516,12 +518,11 @@ very high and the recipient has a phone number::
516518
$this->price = $price;
517519
}
518520

519-
public function getChannels(Recipient $recipient)
521+
public function getChannels(RecipientInterface $recipient)
520522
{
521523
if (
522524
$this->price > 10000
523-
&& $recipient instanceof AdminRecipient
524-
&& null !== $recipient->getPhone()
525+
&& $recipient instanceof SmsRecipientInterface
525526
) {
526527
return ['sms'];
527528
}
@@ -545,7 +546,7 @@ and its ``asChatMessage()`` method::
545546
use Symfony\Component\Notifier\Message\ChatMessage;
546547
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
547548
use Symfony\Component\Notifier\Notification\Notification;
548-
use Symfony\Component\Notifier\Recipient\Recipient;
549+
use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
549550

550551
class InvoiceNotification extends Notification implements ChatNotificationInterface
551552
{
@@ -556,7 +557,7 @@ and its ``asChatMessage()`` method::
556557
$this->price = $price;
557558
}
558559

559-
public function asChatMessage(Recipient $recipient, string $transport = null): ?ChatMessage
560+
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
560561
{
561562
// Add a custom emoji if the message is sent to Slack
562563
if ('slack' === $transport) {

0 commit comments

Comments
 (0)