Files
backupscript/src/Notification/Notification.php

53 lines
1.2 KiB
PHP
Raw Normal View History

2023-06-12 09:30:10 +00:00
<?php
namespace App\Notification;
2023-06-13 08:15:29 +00:00
use App\Notification\Ntfy;
2023-06-12 09:30:10 +00:00
class Notification
{
/**
2023-06-13 08:15:29 +00:00
* @var NotificationInterface[] $notifiers
2023-06-12 09:30:10 +00:00
*/
public array $notifiers = array();
2023-06-13 08:15:29 +00:00
/**
* Load multiple configurations
*
* @param array<array<string>> $config Array of notifier configurations.
*/
2023-06-12 09:30:10 +00:00
public function loadMany(array $config): void
{
2023-06-13 08:15:29 +00:00
foreach ($config as $conf) {
$this->loadSingle($conf['type'], $conf);
2023-06-12 09:30:10 +00:00
}
}
2023-06-13 08:15:29 +00:00
/**
* Load a single configuration
*
* @param string $key Notification class
* @param string[] $config Implementation specific configuration
2023-06-15 14:10:17 +00:00
* @SuppressWarnings(PHPMD)
2023-06-13 08:15:29 +00:00
*/
2023-06-12 09:30:10 +00:00
public function loadSingle(string $key, array $config): void
{
2023-06-13 08:15:29 +00:00
switch ($key) {
case 'ntfy':
case 'Ntfy':
case 'NTFY':
2023-06-15 14:10:17 +00:00
$this->notifiers[] = Ntfy::factory($config);
2023-06-13 08:15:29 +00:00
break;
default:
break;
}
2023-06-12 09:30:10 +00:00
}
public function send(string $title, string $message): void
{
foreach ($this->notifiers as $notifier) {
$notifier->send($title, $message);
}
}
}