33 lines
682 B
PHP
33 lines
682 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Notification;
|
||
|
|
||
|
use Ntfy\Server;
|
||
|
use Ntfy\Message;
|
||
|
use Ntfy\Client;
|
||
|
|
||
|
class Ntfy implements NotificationInterface
|
||
|
{
|
||
|
private array $config;
|
||
|
|
||
|
private \Ntfy\Server $server;
|
||
|
private \Ntfy\Client $client;
|
||
|
|
||
|
public function __construct(array $config)
|
||
|
{
|
||
|
$this->config = $config;
|
||
|
|
||
|
$this->server = new Server($config['domain']);
|
||
|
$this->client = new Client($this->server);
|
||
|
}
|
||
|
|
||
|
public function send(string $title, string $message): void
|
||
|
{
|
||
|
$msg = new Message();
|
||
|
$msg->topic($this->config['topic']);
|
||
|
$msg->title($title);
|
||
|
$msg->body($message);
|
||
|
$this->client->send($msg);
|
||
|
}
|
||
|
}
|