Initial commit
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace FluentMail\App\Services\Notification;
|
||||
|
||||
use FluentMail\App\Models\Settings;
|
||||
use FluentMail\Includes\Support\Arr;
|
||||
use FluentMail\Includes\Core\Application;
|
||||
|
||||
class Manager
|
||||
{
|
||||
protected $app = null;
|
||||
|
||||
protected static $config = [];
|
||||
|
||||
protected static $settings = [];
|
||||
|
||||
public function __construct(?Application $app = null)
|
||||
{
|
||||
$this->app = $app ?: fluentMail();
|
||||
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
$this->loadConfigAndSettings();
|
||||
}
|
||||
|
||||
protected function loadConfigAndSettings()
|
||||
{
|
||||
static::$config = require(__DIR__ . '/config.php');
|
||||
|
||||
static::$settings = (new Settings())->notificationSettings();
|
||||
|
||||
$this->mergeConfigAndSettings();
|
||||
}
|
||||
|
||||
protected function mergeConfigAndSettings()
|
||||
{
|
||||
$databaseSettings = $this->getSettings();
|
||||
|
||||
// Merge database settings with config
|
||||
foreach (static::$config['channels'] as $key => $channel) {
|
||||
$channelSettings = Arr::get($databaseSettings, $key, []);
|
||||
|
||||
if ($channelSettings) {
|
||||
static::$config['channels'][$key]['settings'] = $channelSettings;
|
||||
}
|
||||
}
|
||||
|
||||
// Set active channel from database
|
||||
static::$config['active_channel'] = Arr::get($databaseSettings, 'active_channel', []);
|
||||
}
|
||||
|
||||
public function getConfig($key = null, $default = null)
|
||||
{
|
||||
return $key ? Arr::get(static::$config, $key, $default) : static::$config;
|
||||
}
|
||||
|
||||
public function getSettings($key = null, $default = null)
|
||||
{
|
||||
return $key ? Arr::get(static::$settings, $key, $default) : static::$settings;
|
||||
}
|
||||
|
||||
public function getAllChannels()
|
||||
{
|
||||
return static::$config['channels'] ?? [];
|
||||
}
|
||||
|
||||
public function getChannel($key)
|
||||
{
|
||||
return Arr::get(static::$config['channels'], $key, null);
|
||||
}
|
||||
|
||||
public function getActiveChannels()
|
||||
{
|
||||
static $activeChannels;
|
||||
if (isset($activeChannels)) {
|
||||
return $activeChannels;
|
||||
}
|
||||
|
||||
$activeChannelKeys = Arr::get(static::$config, 'active_channel', []);
|
||||
if (!$activeChannelKeys || !is_array($activeChannelKeys)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$activeChannels = [];
|
||||
|
||||
foreach ($activeChannelKeys as $activeChannelKey) {
|
||||
$channel = $this->getChannel($activeChannelKey);
|
||||
|
||||
if (!$channel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$channelSettings = Arr::get(static::$settings, $activeChannelKey, []);
|
||||
|
||||
if (empty($channelSettings['status']) || $channelSettings['status'] != 'yes') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$channel['driver'] = $activeChannelKey;
|
||||
$channel['settings'] = $channelSettings;
|
||||
|
||||
$activeChannels[] = $channel;
|
||||
}
|
||||
|
||||
return $activeChannels;
|
||||
}
|
||||
|
||||
public function getChannelStatus($key)
|
||||
{
|
||||
$channelSettings = Arr::get(static::$settings, $key, []);
|
||||
return Arr::get($channelSettings, 'status', 'no');
|
||||
}
|
||||
|
||||
public function getAllChannelKeys()
|
||||
{
|
||||
return array_keys(static::$config['channels'] ?? []);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'channels' => [
|
||||
'telegram' => [
|
||||
'key' => 'telegram',
|
||||
'title' => __('Telegram', 'fluent-smtp'),
|
||||
'logo' => fluentMailAssetUrl('images/tele.svg'),
|
||||
'logo_name' => 'tele.svg',
|
||||
'controller' => 'FluentMail\App\Http\Controllers\TelegramController',
|
||||
'component' => '_TelegramNotification',
|
||||
'info_component' => '_TelegramConnectionInfo',
|
||||
'routes' => [
|
||||
'register' => 'settings/telegram/issue-pin-code',
|
||||
'confirm' => 'settings/telegram/confirm',
|
||||
'info' => 'settings/telegram/info',
|
||||
'test' => 'settings/telegram/send-test',
|
||||
'disconnect' => 'settings/telegram/disconnect',
|
||||
],
|
||||
],
|
||||
'slack' => [
|
||||
'key' => 'slack',
|
||||
'title' => __('Slack', 'fluent-smtp'),
|
||||
'logo' => fluentMailAssetUrl('images/slack.svg'),
|
||||
'logo_name' => 'slack.svg',
|
||||
'controller' => 'FluentMail\App\Http\Controllers\SlackController',
|
||||
'component' => '_SlackNotification',
|
||||
'info_component' => '_SlackWebhookInfo',
|
||||
'routes' => [
|
||||
'register' => 'settings/slack/register',
|
||||
'test' => 'settings/slack/send-test',
|
||||
'disconnect' => 'settings/slack/disconnect',
|
||||
],
|
||||
],
|
||||
'discord' => [
|
||||
'key' => 'discord',
|
||||
'title' => __('Discord', 'fluent-smtp'),
|
||||
'logo' => fluentMailAssetUrl('images/disc.svg'),
|
||||
'logo_name' => 'disc.svg',
|
||||
'controller' => 'FluentMail\App\Http\Controllers\DiscordController',
|
||||
'component' => '_DiscordNotification',
|
||||
'info_component' => '_DiscordWebhookInfo',
|
||||
'routes' => [
|
||||
'register' => 'settings/discord/register',
|
||||
'test' => 'settings/discord/send-test',
|
||||
'disconnect' => 'settings/discord/disconnect',
|
||||
],
|
||||
],
|
||||
'pushover' => [
|
||||
'key' => 'pushover',
|
||||
'title' => __('Pushover', 'fluent-smtp'),
|
||||
'logo' => fluentMailAssetUrl('images/pushover.svg'),
|
||||
'logo_name' => 'pushover.svg',
|
||||
'controller' => 'FluentMail\App\Http\Controllers\PushoverController',
|
||||
'component' => '_PushoverNotification',
|
||||
'info_component' => '_PushoverWebhookInfo',
|
||||
'routes' => [
|
||||
'register' => 'settings/pushover/register',
|
||||
'test' => 'settings/pushover/send-test',
|
||||
'disconnect' => 'settings/pushover/disconnect',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
Reference in New Issue
Block a user