This commit is contained in:
@ -50,6 +50,9 @@ class Notification
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single notifier instance.
|
||||
*/
|
||||
public function addNotifier(NotificationInterface $instance): void
|
||||
{
|
||||
$this->notifiers[] = $instance;
|
||||
@ -65,6 +68,11 @@ class Notification
|
||||
return $this->notifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a notification to all notifiers.
|
||||
*
|
||||
* Logs an error if sending fails.
|
||||
*/
|
||||
public function send(string $title, string $message): void
|
||||
{
|
||||
foreach ($this->getNotifiers() as $notifier) {
|
||||
|
@ -11,5 +11,8 @@ interface NotificationInterface
|
||||
*/
|
||||
public static function factory(array $config): self;
|
||||
|
||||
/**
|
||||
* @throw Exception on error.
|
||||
*/
|
||||
public function send(string $title, string $message): void;
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ use Ntfy\Message;
|
||||
use Ntfy\Client;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Send a notification through a ntfy server
|
||||
*/
|
||||
class Ntfy implements NotificationInterface
|
||||
{
|
||||
private string $topic = 'default';
|
||||
@ -16,6 +19,8 @@ class Ntfy implements NotificationInterface
|
||||
/**
|
||||
* Initialize with configuration.
|
||||
*
|
||||
* Factory method.
|
||||
*
|
||||
* @param string[] $config Configuration
|
||||
*/
|
||||
public static function factory(array $config): self
|
||||
@ -34,6 +39,11 @@ class Ntfy implements NotificationInterface
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
@ -43,6 +53,9 @@ class Ntfy implements NotificationInterface
|
||||
$this->topic = $topic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently set topic.
|
||||
*/
|
||||
public function getTopic(): string
|
||||
{
|
||||
return $this->topic;
|
||||
|
Reference in New Issue
Block a user