2023-06-12 09:30:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notification;
|
|
|
|
|
|
|
|
use Ntfy\Server;
|
|
|
|
use Ntfy\Message;
|
|
|
|
use Ntfy\Client;
|
|
|
|
|
|
|
|
class Ntfy implements NotificationInterface
|
|
|
|
{
|
2023-06-13 08:15:29 +00:00
|
|
|
/** @var string[] $config */
|
2023-06-12 09:30:10 +00:00
|
|
|
private array $config;
|
|
|
|
|
2023-06-13 08:15:29 +00:00
|
|
|
private Client $client;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize with configuration.
|
|
|
|
*
|
|
|
|
* @param string[] $config Configuration
|
|
|
|
*/
|
2023-06-12 09:30:10 +00:00
|
|
|
public function __construct(array $config)
|
|
|
|
{
|
|
|
|
$this->config = $config;
|
|
|
|
|
2023-06-13 08:15:29 +00:00
|
|
|
$this->client = new Client(new Server($config['domain']));
|
2023-06-12 09:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|