-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathNotifier.php
More file actions
121 lines (108 loc) · 2.7 KB
/
Copy pathNotifier.php
File metadata and controls
121 lines (108 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace Bow\Notifier;
use Bow\Database\Barry\Model;
use Bow\Mail\Envelop;
use Bow\Notifier\Adapters\DatabaseChannelAdapter;
use Bow\Notifier\Adapters\MailChannelAdapter;
use Bow\Notifier\Adapters\SlackChannelAdapter;
use Bow\Notifier\Adapters\SmsChannelAdapter;
use Bow\Notifier\Adapters\TelegramChannelAdapter;
abstract class Notifier
{
/**
* Defines the available channel
*
* @var array
*/
private static array $channels = [
"mail" => MailChannelAdapter::class,
"database" => DatabaseChannelAdapter::class,
"telegram" => TelegramChannelAdapter::class,
"slack" => SlackChannelAdapter::class,
"sms" => SmsChannelAdapter::class,
];
/**
* Push channels to the messaging
*
* @param array $channels
* @return array
*/
public static function pushChannels(array $channels): array
{
static::$channels = array_merge(static::$channels, $channels);
return self::$channels;
}
/**
* Send notification to mail
*
* @param Model $context
* @return Envelop|null
*/
public function toMail(Model $context): ?Envelop
{
return null;
}
/**
* Send notification to database
*
* @param Model $context
* @return array
*/
public function toDatabase(Model $context): array
{
return [];
}
/**
* Send notification to sms
*
* @param Model $context
* @return array{to: string, message: string}
*/
public function toSms(Model $context): array
{
return [];
}
/**
* Send notification to slack
*
* @param Model $context
* @return array{webhook_url: ?string, content: array}
*/
public function toSlack(Model $context): array
{
return [];
}
/**
* Send notification to telegram
*
* @param Model $context
* @return array{message: string, chat_id: string, parse_mode: string}
*/
public function toTelegram(Model $context): array
{
return [];
}
/**
* Process the notification
*
* @param Model $context
* @return void
*/
public function process(Model $context): void
{
$channels = $this->channels($context);
foreach ($channels as $channel) {
if (array_key_exists($channel, static::$channels)) {
$target_channel = new static::$channels[$channel]();
$target_channel->send($context, $this);
}
}
}
/**
* Returns the available channels to be used
*
* @param Model $context
* @return array
*/
abstract public function channels(Model $context): array;
}