Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 12
SmsChannel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 12
 notify
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 11
 supports
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Notifier\Channel;
13
14use Symfony\Component\Notifier\Message\SmsMessage;
15use Symfony\Component\Notifier\Notification\Notification;
16use Symfony\Component\Notifier\Notification\SmsNotificationInterface;
17use Symfony\Component\Notifier\Recipient\Recipient;
18use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
19
20/**
21 * @author Fabien Potencier <fabien@symfony.com>
22 *
23 * @experimental in 5.1
24 */
25class SmsChannel extends AbstractChannel
26{
27    public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
28    {
29        $message = null;
30        if ($notification instanceof SmsNotificationInterface) {
31            $message = $notification->asSmsMessage($recipient, $transportName);
32        }
33
34        if (null === $message) {
35            $message = SmsMessage::fromNotification($notification, $recipient);
36        }
37
38        if (null !== $transportName) {
39            $message->transport($transportName);
40        }
41
42        if (null === $this->bus) {
43            $this->transport->send($message);
44        } else {
45            $this->bus->dispatch($message);
46        }
47    }
48
49    public function supports(Notification $notification, Recipient $recipient): bool
50    {
51        return $recipient instanceof SmsRecipientInterface && '' !== $recipient->getPhone();
52    }
53}