| @@ 9-41 (lines=33) @@ | ||
| 6 | use IrishDan\NotificationBundle\Exception\MessageFormatException; |
|
| 7 | use IrishDan\NotificationBundle\Notification\NotificationInterface; |
|
| 8 | ||
| 9 | class MailDataFormatter extends BaseFormatter implements MessageFormatterInterface |
|
| 10 | { |
|
| 11 | const CHANNEL = 'mail'; |
|
| 12 | private $mailConfiguration; |
|
| 13 | ||
| 14 | public function __construct(array $mailConfiguration) |
|
| 15 | { |
|
| 16 | $this->mailConfiguration = $mailConfiguration; |
|
| 17 | } |
|
| 18 | ||
| 19 | public function format(NotificationInterface $notification) |
|
| 20 | { |
|
| 21 | $notification->setChannel(self::CHANNEL); |
|
| 22 | parent::format($notification); |
|
| 23 | ||
| 24 | /** @var EmailableInterface $notifiable */ |
|
| 25 | $notifiable = $notification->getNotifiable(); |
|
| 26 | if (!$notifiable instanceof EmailableInterface) { |
|
| 27 | $this->createFormatterException(EmailableInterface::class, self::CHANNEL); |
|
| 28 | } |
|
| 29 | ||
| 30 | // Build the dispatch data array. |
|
| 31 | $dispatchData = [ |
|
| 32 | 'to' => $notifiable->getEmail(), |
|
| 33 | 'from' => empty($this->mailConfiguration['default_sender']) ? '' : $this->mailConfiguration['default_sender'], |
|
| 34 | ]; |
|
| 35 | ||
| 36 | $messageData = self::createMessagaData($notification->getDataArray()); |
|
| 37 | $message = self::createMessage($dispatchData, $messageData, self::CHANNEL); |
|
| 38 | ||
| 39 | return $message; |
|
| 40 | } |
|
| 41 | } |
|
| @@ 9-41 (lines=33) @@ | ||
| 6 | use IrishDan\NotificationBundle\Notification\NotificationInterface; |
|
| 7 | use IrishDan\NotificationBundle\TextableInterface; |
|
| 8 | ||
| 9 | class NexmoDataFormatter extends BaseFormatter implements MessageFormatterInterface |
|
| 10 | { |
|
| 11 | const CHANNEL = 'nexmo'; |
|
| 12 | protected $nexmoConfiguration; |
|
| 13 | ||
| 14 | public function __construct(array $nexmoConfiguration = []) |
|
| 15 | { |
|
| 16 | $this->nexmoConfiguration = $nexmoConfiguration; |
|
| 17 | } |
|
| 18 | ||
| 19 | public function format(NotificationInterface $notification) |
|
| 20 | { |
|
| 21 | $notification->setChannel(self::CHANNEL); |
|
| 22 | parent::format($notification); |
|
| 23 | ||
| 24 | /** @var TextableInterface $notifiable */ |
|
| 25 | $notifiable = $notification->getNotifiable(); |
|
| 26 | if (!$notifiable instanceof TextableInterface) { |
|
| 27 | $this->createFormatterException(TextableInterface::class, self::CHANNEL); |
|
| 28 | } |
|
| 29 | ||
| 30 | // Build the dispatch data array. |
|
| 31 | $dispatchData = [ |
|
| 32 | 'to' => $notifiable->getNumber(), |
|
| 33 | 'from' => empty($this->nexmoConfiguration['from']) ? '' : $this->nexmoConfiguration['from'], |
|
| 34 | ]; |
|
| 35 | ||
| 36 | $messageData = self::createMessagaData($notification->getDataArray()); |
|
| 37 | $message = self::createMessage($dispatchData, $messageData, self::CHANNEL); |
|
| 38 | ||
| 39 | return $message; |
|
| 40 | } |
|
| 41 | } |
|