This commit is contained in:
@ -8,27 +8,41 @@ use Ntfy\Client;
|
||||
|
||||
class Ntfy implements NotificationInterface
|
||||
{
|
||||
/** @var string[] $config */
|
||||
private array $config;
|
||||
|
||||
private Client $client;
|
||||
|
||||
private string $topic = 'default';
|
||||
/**
|
||||
* Initialize with configuration.
|
||||
*
|
||||
* @param string[] $config Configuration
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
public static function factory(array $config): self
|
||||
{
|
||||
$this->config = $config;
|
||||
$instance = new self(new Client(new Server($config['domain'])));
|
||||
if (isset($config['topic'])) {
|
||||
$instance->setTopic($config['topic']);
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
$this->client = new Client(new Server($config['domain']));
|
||||
public function __construct(Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function setTopic(string $topic): void
|
||||
{
|
||||
$this->topic = $topic;
|
||||
}
|
||||
|
||||
public function send(string $title, string $message): void
|
||||
{
|
||||
assert(strlen($title) > 0);
|
||||
assert(strlen($title) < 256);
|
||||
assert(strlen($message) > 0);
|
||||
assert(strlen($message) < 4096);
|
||||
|
||||
$msg = new Message();
|
||||
$msg->topic($this->config['topic']);
|
||||
$msg->topic($this->topic);
|
||||
$msg->title($title);
|
||||
$msg->body($message);
|
||||
$this->client->send($msg);
|
||||
|
Reference in New Issue
Block a user