1 | <?php |
||
2 | |||
3 | namespace CSlant\TelegramGitNotifier; |
||
4 | |||
5 | use CSlant\TelegramGitNotifier\Constants\EventConstant; |
||
6 | use CSlant\TelegramGitNotifier\Constants\NotificationConstant; |
||
7 | use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException; |
||
8 | use CSlant\TelegramGitNotifier\Interfaces\EventInterface; |
||
9 | use CSlant\TelegramGitNotifier\Interfaces\Structures\NotificationInterface; |
||
10 | use CSlant\TelegramGitNotifier\Models\Event; |
||
11 | use CSlant\TelegramGitNotifier\Structures\App; |
||
12 | use CSlant\TelegramGitNotifier\Structures\Notification; |
||
13 | use CSlant\TelegramGitNotifier\Trait\EventTrait; |
||
14 | use GuzzleHttp\Client; |
||
15 | use Telegram; |
||
16 | |||
17 | class Notifier implements NotificationInterface, EventInterface |
||
18 | { |
||
19 | use App; |
||
20 | use Notification; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
21 | |||
22 | use EventTrait; |
||
0 ignored issues
–
show
|
|||
23 | |||
24 | public Event $event; |
||
25 | |||
26 | public Client $client; |
||
27 | |||
28 | /** |
||
29 | * @param Telegram|null $telegram |
||
30 | * @param string|null $chatBotId |
||
31 | * @param Event|null $event |
||
32 | * @param string|null $platform |
||
33 | * @param string|null $platformFile |
||
34 | * @param Client|null $client |
||
35 | * |
||
36 | * @throws ConfigFileException |
||
37 | */ |
||
38 | public function __construct( |
||
39 | Telegram $telegram = null, |
||
40 | ?string $chatBotId = null, |
||
41 | Event $event = null, |
||
42 | ?string $platform = EventConstant::DEFAULT_PLATFORM, |
||
43 | ?string $platformFile = null, |
||
44 | Client $client = null, |
||
45 | ) { |
||
46 | $this->event = $event ?? new Event(); |
||
47 | $this->setPlatFormForEvent($platform, $platformFile); |
||
48 | $this->validatePlatformFile(); |
||
49 | |||
50 | $this->telegram = $telegram ?? new Telegram(config('telegram-git-notifier.bot.token')); |
||
51 | $this->setCurrentChatBotId($chatBotId); |
||
52 | |||
53 | $this->client = $client ?? new Client(); |
||
54 | } |
||
55 | |||
56 | public function parseNotifyChatIds(?string $chatIds = null): array |
||
57 | { |
||
58 | $chatData = explode( |
||
59 | NotificationConstant::CHAT_ID_PAIRS_SEPARATOR, |
||
60 | $chatIds ?? config('telegram-git-notifier.bot.notify_chat_ids') |
||
61 | ); |
||
62 | $chatThreadMapping = []; |
||
63 | |||
64 | foreach ($chatData as $data) { |
||
65 | [$chatId, $threadIds] = explode(NotificationConstant::CHAT_THREAD_ID_SEPARATOR, $data) + [null, null]; |
||
66 | $chatThreadMapping[$chatId] = $threadIds |
||
67 | ? explode(NotificationConstant::THREAD_ID_SEPARATOR, $threadIds) |
||
68 | : []; |
||
69 | } |
||
70 | |||
71 | return $chatThreadMapping; |
||
72 | } |
||
73 | } |
||
74 |