More documentation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2023-09-19 06:34:20 +00:00
parent f5a34213b5
commit 876702473c
4 changed files with 49 additions and 25 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;