setTopic($config['topic']); } return $instance; } /** * @todo The constructor should be private but static code analysis complains. */ public function __construct(private Client $client) { } /** * Set the topic of the notification message. * * @param string $topic Topic length between 1 and 256 characters. */ public function setTopic(string $topic): void { if (strlen($topic) < 1 || strlen($topic) >= 256) { throw new InvalidArgumentException("Invalid topic length"); } $this->topic = $topic; } /** * Return the currently set topic. */ public function getTopic(): string { return $this->topic; } /** * Push a message with Ntfy */ public function send(string $title, string $message): void { if (strlen($title) < 1 || strlen($title) >= 256) { throw new InvalidArgumentException("Invalid title length"); } if (strlen($message) < 1 || strlen($message) >= 4096) { throw new InvalidArgumentException("Invalid message length"); } $msg = new Message(); $msg->topic($this->getTopic()); $msg->title($title); $msg->body($message); $this->client->send($msg); } }