laravel-notification-channels /
smspoh
| 1 | <?php |
||
| 2 | |||
| 3 | namespace NotificationChannels\Smspoh; |
||
| 4 | |||
| 5 | use Illuminate\Notifications\Notification; |
||
| 6 | use NotificationChannels\Smspoh\Exceptions\CouldNotSendNotification; |
||
| 7 | |||
| 8 | class SmspohChannel |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The Smspoh client instance. |
||
| 12 | * |
||
| 13 | * @var SmspohApi |
||
| 14 | */ |
||
| 15 | protected $smspoh; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The phone number notifications should be sent from. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $sender; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var int |
||
| 26 | * The message body content count should be no longer than 6 message parts(918). |
||
| 27 | */ |
||
| 28 | protected $character_limit_count = 918; |
||
| 29 | |||
| 30 | 5 | public function __construct(SmspohApi $smspoh, $sender) |
|
| 31 | { |
||
| 32 | 5 | $this->smspoh = $smspoh; |
|
| 33 | 5 | $this->sender = $sender; |
|
| 34 | 5 | } |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Send the given notification. |
||
| 38 | * |
||
| 39 | * @param mixed $notifiable |
||
| 40 | * @param Notification $notification |
||
| 41 | * |
||
| 42 | * @return mixed|\Psr\Http\Message\ResponseInterface|void |
||
| 43 | * @throws CouldNotSendNotification |
||
| 44 | */ |
||
| 45 | 5 | public function send($notifiable, Notification $notification) |
|
| 46 | { |
||
| 47 | 5 | if (! $to = $notifiable->routeNotificationFor('smspoh', $notification)) { |
|
| 48 | 1 | return; |
|
| 49 | } |
||
| 50 | |||
| 51 | 4 | $message = $notification->toSmspoh($notifiable); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 52 | |||
| 53 | 4 | if (is_string($message)) { |
|
| 54 | 1 | $message = new SmspohMessage($message); |
|
| 55 | } |
||
| 56 | |||
| 57 | 4 | if (mb_strlen($message->content) > $this->character_limit_count) { |
|
| 58 | 1 | throw CouldNotSendNotification::contentLengthLimitExceeded($this->character_limit_count); |
|
| 59 | } |
||
| 60 | |||
| 61 | 3 | return $this->smspoh->send([ |
|
| 62 | 3 | 'sender' => $message->sender ?: $this->sender, |
|
| 63 | 3 | 'to' => $to, |
|
| 64 | 3 | 'message' => trim($message->content), |
|
| 65 | 3 | 'test' => $message->test ?: false, |
|
| 66 | ]); |
||
| 67 | } |
||
| 68 | } |
||
| 69 |