Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class InvoicePaid implements NotificationInterface
public function exportForDatabase()
{
return \Yii::createObject([
'class' => '\tuyakhov\notifications\messages\DatabaseChannel',
'class' => '\tuyakhov\notifications\messages\DatabaseMessage',
'subject' => "Invoice has been paid",
'body' => "Your invoice #{$this->invoice->id} has been paid",
'data' => [
Expand Down Expand Up @@ -212,4 +212,4 @@ foreach($model->unreadNotifications as $notification) {
$notification->isUnread();
$notification->isRead();
}
```
```
9 changes: 5 additions & 4 deletions src/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Notifier extends Component
/**
* Sends the given notifications through available channels to the given notifiable entities.
* You may pass an array in order to send multiple notifications to multiple recipients.
*
*
* @param array|NotifiableInterface $recipients the recipients that can receive given notifications.
* @param array|NotificationInterface $notifications the notification that should be delivered.
* @return void
Expand All @@ -77,14 +77,14 @@ public function send($recipients, $notifications)
*/
$recipients = [$recipients];
}

if (!is_array($notifications)){
/**
* @var $notifications NotificationInterface[]
*/
$notifications = [$notifications];
}

foreach ($recipients as $recipient) {
$channels = array_intersect($recipient->viaChannels(), array_keys($this->channels));
foreach ($notifications as $notification) {
Expand All @@ -99,6 +99,7 @@ public function send($recipients, $notifications)
\Yii::info("Sending notification " . get_class($notification) . " to " . get_class($recipient) . " via {$channel}", __METHOD__);
$response = $channelInstance->send($recipient, $notification);
} catch (\Exception $e) {
\Yii::error($e->getMessage());
$response = $e;
}
$this->trigger(self::EVENT_AFTER_SEND, new NotificationEvent([
Expand Down Expand Up @@ -128,4 +129,4 @@ protected function getChannelInstance($channel)
}
return $this->channels[$channel];
}
}
}