1 | <?php |
||
8 | class SmscRuChannel |
||
9 | { |
||
10 | /** @var SmscRuApi */ |
||
11 | protected $smsc; |
||
12 | |||
13 | 5 | public function __construct(SmscRuApi $smsc) |
|
17 | |||
18 | /** |
||
19 | * Send the given notification. |
||
20 | * |
||
21 | * @param mixed $notifiable |
||
22 | * @param Notification $notification |
||
23 | * |
||
24 | * @throws CouldNotSendNotification |
||
25 | * |
||
26 | * @return array|null |
||
27 | */ |
||
28 | 5 | public function send($notifiable, Notification $notification): ?array |
|
29 | { |
||
30 | 5 | $message = $notification->{'toSmscRu'}($notifiable); |
|
31 | |||
32 | 5 | if (\is_string($message)) { |
|
33 | $message = new SmscRuMessage($message); |
||
34 | } |
||
35 | |||
36 | 5 | $to = $message->to; |
|
37 | |||
38 | 5 | if (empty($to)) { |
|
39 | 4 | if (! ($to = $this->getRecipients($notifiable, $notification))) { |
|
40 | 1 | return null; |
|
41 | } |
||
42 | } |
||
43 | |||
44 | 4 | return $this->sendMessage($to, $message); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Gets a list of phones from the given notifiable. |
||
49 | * |
||
50 | * @param mixed $notifiable |
||
51 | * @param Notification $notification |
||
52 | * |
||
53 | * @return string[] |
||
54 | */ |
||
55 | 4 | protected function getRecipients($notifiable, Notification $notification): array |
|
65 | |||
66 | 4 | protected function sendMessage($recipients, SmscRuMessage $message) |
|
84 | } |
||
85 |