setTopic($config['topic']); } return $instance; } public function __construct(private Client $client) { } /** * Set the topic of the notification message. * * @param string $topic Topic length between 1 and TOPIC_MAX_LENGTH characters. */ public function setTopic(string $topic): void { if (! strlen($topic) || strlen($topic) > self::TOPIC_MAX_LENGTH) { 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) || strlen($title) > self::TITLE_MAX_LENGTH) { throw new InvalidArgumentException("Invalid title length"); } if (! strlen($message) || strlen($message) > self::MESSAGE_MAX_LENGTH) { throw new InvalidArgumentException("Invalid message length"); } $msg = new Message(); $msg->topic($this->getTopic()); $msg->title($title); $msg->body($message); $this->client->send($msg); } }