1
1
<?php
2
2
3
- declare (strict_types=1 );
4
-
5
3
namespace CSlant \LaravelTelegramGitNotifier \Http \Actions ;
6
4
7
5
use CSlant \LaravelTelegramGitNotifier \Services \CallbackService ;
17
15
use CSlant \TelegramGitNotifier \Exceptions \SendNotificationException ;
18
16
use CSlant \TelegramGitNotifier \Notifier ;
19
17
use GuzzleHttp \Client ;
20
- use GuzzleHttp \ClientInterface ;
21
18
use Symfony \Component \HttpFoundation \Request ;
22
- use Telegram \ Telegram as TelegramSDK ;
19
+ use Telegram ;
23
20
24
21
class IndexAction
25
22
{
26
- public function __construct (
27
- private ClientInterface $ client ,
28
- private Bot $ bot,
29
- private Notifier $ notifier ,
30
- private Request $ request
31
- ) {
32
- }
23
+ protected Client $ client ;
24
+
25
+ protected Bot $ bot;
26
+
27
+ protected Notifier $ notifier ;
28
+
29
+ protected Request $ request ;
33
30
34
31
/**
35
- * Create a new instance with default dependencies.
36
- *
37
32
* @throws ConfigFileException
38
33
*/
39
- public static function createDefault (): self
34
+ public function __construct ()
40
35
{
41
- return new self (
42
- new Client (),
43
- new Bot (new TelegramSDK (config ('telegram-git-notifier.bot.token ' ))),
44
- new Notifier (),
45
- Request::createFromGlobals ()
46
- );
36
+ $ this ->client = new Client ();
37
+
38
+ $ telegram = new Telegram (config ('telegram-git-notifier.bot.token ' ));
39
+ $ this ->bot = new Bot ($ telegram );
40
+ $ this ->notifier = new Notifier ();
47
41
}
48
42
49
43
/**
50
44
* Handle telegram git notifier app.
51
45
*
46
+ * @return void
47
+ *
52
48
* @throws InvalidViewTemplateException
53
49
* @throws MessageIsEmptyException
54
50
* @throws SendNotificationException
@@ -59,69 +55,23 @@ public static function createDefault(): self
59
55
public function __invoke (): void
60
56
{
61
57
if ($ this ->bot ->isCallback ()) {
62
- $ this ->handleCallback ();
63
- return ;
64
- }
58
+ $ callbackAction = new CallbackService ($ this ->bot );
59
+ $ callbackAction ->handle ();
65
60
66
- if ($ this ->shouldHandleCommand ()) {
67
- $ this ->handleCommand ();
68
61
return ;
69
62
}
70
63
71
- $ this ->handleNotification ();
72
- }
73
-
74
- /**
75
- * Handle callback actions.
76
- *
77
- * @throws CallbackException
78
- * @throws EntryNotFoundException
79
- * @throws InvalidViewTemplateException
80
- * @throws MessageIsEmptyException
81
- */
82
- private function handleCallback (): void
83
- {
84
- $ callbackAction = new CallbackService ($ this ->bot );
85
- $ callbackAction ->handle ();
86
- }
64
+ if ($ this ->bot ->isMessage () && $ this ->bot ->isOwner ()) {
65
+ $ commandAction = new CommandService ($ this ->bot );
66
+ $ commandAction ->handle ();
87
67
88
- /**
89
- * Handle command messages.
90
- *
91
- * @throws EntryNotFoundException
92
- * @throws MessageIsEmptyException
93
- */
94
- private function handleCommand (): void
95
- {
96
- if (!$ this ->bot ->isMessage () || !$ this ->bot ->isOwner ()) {
97
68
return ;
98
69
}
99
70
100
- $ commandAction = new CommandService ($ this ->bot );
101
- $ commandAction ->handle ();
102
- }
103
-
104
- /**
105
- * Handle notification sending.
106
- *
107
- * @throws InvalidViewTemplateException
108
- * @throws MessageIsEmptyException
109
- * @throws SendNotificationException
110
- */
111
- private function handleNotification (): void
112
- {
113
- $ notificationService = new NotificationService (
71
+ $ sendNotification = new NotificationService (
114
72
$ this ->notifier ,
115
73
$ this ->bot ->setting
116
74
);
117
- $ notificationService ->handle ();
118
- }
119
-
120
- /**
121
- * Check if the current message should be handled as a command.
122
- */
123
- private function shouldHandleCommand (): bool
124
- {
125
- return $ this ->bot ->isMessage () && $ this ->bot ->isOwner ();
75
+ $ sendNotification ->handle ();
126
76
}
127
77
}
0 commit comments