Skip to content

Commit

Permalink
feat: integrate the notification channel
Browse files Browse the repository at this point in the history
  • Loading branch information
papac committed Jan 18, 2025
1 parent 71da8ba commit ba182ad
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/Notification/Channel/ChannelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ interface ChannelInterface
/**
* Send the notification
*
* @param mixed $message
* @return void
*/
public function send(mixed $message): void;
public function send(): void;
}
11 changes: 8 additions & 3 deletions src/Notification/Channel/DatabaseChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

namespace Bow\Notification\Channel;

use Bow\Notification\Channel\ChannelInterface;
use Bow\Database\Database;

class DatabaseChannel implements ChannelInterface
{
public function __construct(
private readonly array $database
) {
}

/**
* Send the notification to database
*
* @param mixed $message
* @return void
*/
public function send(mixed $message): void
public function send(): void
{
Database::table('notifications')->insert($this->database);
}
}
18 changes: 13 additions & 5 deletions src/Notification/Channel/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@

class MailChannel implements ChannelInterface
{
/**
* Set the configured message
*
* @param Message $message
* @return void
*/
public function __construct(
private readonly Message $message
) {
}

/**
* Send the notification to mail
*
* @param mixed $message
* @return void
*/
public function send(mixed $message): void
public function send(): void
{
if ($message instanceof Message) {
Mail::getInstance()->send($message);
}
Mail::getInstance()->send($this->message);
}
}
4 changes: 2 additions & 2 deletions src/Notification/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ final function process(Model $notifiable): void
foreach ($channels as $channel) {
if (array_key_exists($channel, $this->channels)) {
$result = $this->{"to" . ucfirst($channel)}($notifiable);
$target_channel = new $this->channels[$channel]();
$target_channel->send($result);
$target_channel = new $this->channels[$channel]($result);
$target_channel->send();
}
}
}
Expand Down

0 comments on commit ba182ad

Please sign in to comment.