1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace TgBotApi\BotApiBase\Helper; |
6
|
|
|
|
7
|
|
|
use TgBotApi\BotApiBase\Exception\NormalizationException; |
8
|
|
|
use TgBotApi\BotApiBase\Exception\ResponseException; |
9
|
|
|
use TgBotApi\BotApiBase\Method\GetChatAdministratorsMethod; |
10
|
|
|
use TgBotApi\BotApiBase\Method\GetChatMemberMethod; |
11
|
|
|
use TgBotApi\BotApiBase\Method\GetChatMembersCountMethod; |
12
|
|
|
use TgBotApi\BotApiBase\Method\GetChatMethod; |
13
|
|
|
use TgBotApi\BotApiBase\Method\GetFileMethod; |
14
|
|
|
use TgBotApi\BotApiBase\Method\GetGameHighScoresMethod; |
15
|
|
|
use TgBotApi\BotApiBase\Method\GetMeMethod; |
16
|
|
|
use TgBotApi\BotApiBase\Method\GetStickerSetMethod; |
17
|
|
|
use TgBotApi\BotApiBase\Method\GetUpdatesMethod; |
18
|
|
|
use TgBotApi\BotApiBase\Method\GetUserProfilePhotosMethod; |
19
|
|
|
use TgBotApi\BotApiBase\Method\GetWebhookInfoMethod; |
20
|
|
|
use TgBotApi\BotApiBase\Type\ChatMemberType; |
21
|
|
|
use TgBotApi\BotApiBase\Type\ChatType; |
22
|
|
|
use TgBotApi\BotApiBase\Type\FileType; |
23
|
|
|
use TgBotApi\BotApiBase\Type\GameHighScoreType; |
24
|
|
|
use TgBotApi\BotApiBase\Type\StickerSetType; |
25
|
|
|
use TgBotApi\BotApiBase\Type\UpdateType; |
26
|
|
|
use TgBotApi\BotApiBase\Type\UserProfilePhotosType; |
27
|
|
|
use TgBotApi\BotApiBase\Type\UserType; |
28
|
|
|
use TgBotApi\BotApiBase\Type\WebhookInfoType; |
29
|
|
|
|
30
|
|
|
trait GetMethodTrait |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @param $method |
34
|
|
|
* @param $type |
35
|
|
|
* |
36
|
|
|
* @throws ResponseException |
37
|
|
|
* @throws NormalizationException |
38
|
|
|
* |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
|
|
abstract public function call($method, $type = null); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param GetUpdatesMethod $method |
45
|
|
|
* |
46
|
|
|
* @throws ResponseException |
47
|
|
|
* @throws NormalizationException |
48
|
|
|
* |
49
|
|
|
* @return UpdateType[] |
50
|
|
|
*/ |
51
|
2 |
|
public function getUpdates(GetUpdatesMethod $method): array |
52
|
|
|
{ |
53
|
2 |
|
return $this->call($method, UpdateType::class . '[]'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param GetMeMethod $method |
58
|
|
|
* |
59
|
|
|
* @throws ResponseException |
60
|
|
|
* @throws NormalizationException |
61
|
|
|
* |
62
|
|
|
* @return UserType |
63
|
|
|
*/ |
64
|
2 |
|
public function getMe(GetMeMethod $method): UserType |
65
|
|
|
{ |
66
|
2 |
|
return $this->call($method, UserType::class); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param GetUserProfilePhotosMethod $method |
71
|
|
|
* |
72
|
|
|
* @throws ResponseException |
73
|
|
|
* @throws NormalizationException |
74
|
|
|
* |
75
|
|
|
* @return UserProfilePhotosType |
76
|
|
|
*/ |
77
|
2 |
|
public function getUserProfilePhotos(GetUserProfilePhotosMethod $method): UserProfilePhotosType |
78
|
|
|
{ |
79
|
2 |
|
return $this->call($method, UserProfilePhotosType::class); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param GetWebhookInfoMethod $method |
84
|
|
|
* |
85
|
|
|
* @throws ResponseException |
86
|
|
|
* @throws NormalizationException |
87
|
|
|
* |
88
|
|
|
* @return WebhookInfoType |
89
|
|
|
*/ |
90
|
1 |
|
public function getWebhookInfo(GetWebhookInfoMethod $method): WebhookInfoType |
91
|
|
|
{ |
92
|
1 |
|
return $this->call($method, WebhookInfoType::class); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param GetChatMembersCountMethod $method |
97
|
|
|
* |
98
|
|
|
* @throws ResponseException |
99
|
|
|
* @throws NormalizationException |
100
|
|
|
* |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
1 |
|
public function getChatMembersCount(GetChatMembersCountMethod $method): int |
104
|
|
|
{ |
105
|
1 |
|
return $this->call($method); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param GetChatMethod $method |
110
|
|
|
* |
111
|
|
|
* @throws ResponseException |
112
|
|
|
* @throws NormalizationException |
113
|
|
|
* |
114
|
|
|
* @return ChatType |
115
|
|
|
*/ |
116
|
2 |
|
public function getChat(GetChatMethod $method): ChatType |
117
|
|
|
{ |
118
|
2 |
|
return $this->call($method, ChatType::class); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param GetChatAdministratorsMethod $method |
123
|
|
|
* |
124
|
|
|
* @throws ResponseException |
125
|
|
|
* @throws NormalizationException |
126
|
|
|
* |
127
|
|
|
* @return ChatMemberType[] |
128
|
|
|
*/ |
129
|
2 |
|
public function getChatAdministrators(GetChatAdministratorsMethod $method): array |
130
|
|
|
{ |
131
|
2 |
|
return $this->call($method, ChatMemberType::class . '[]'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param GetChatMemberMethod $method |
136
|
|
|
* |
137
|
|
|
* @throws ResponseException |
138
|
|
|
* @throws NormalizationException |
139
|
|
|
* |
140
|
|
|
* @return ChatMemberType |
141
|
|
|
*/ |
142
|
2 |
|
public function getChatMember(GetChatMemberMethod $method): ChatMemberType |
143
|
|
|
{ |
144
|
2 |
|
return $this->call($method, ChatMemberType::class); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param GetGameHighScoresMethod $method |
149
|
|
|
* |
150
|
|
|
* @throws NormalizationException |
151
|
|
|
* @throws ResponseException |
152
|
|
|
* |
153
|
|
|
* @return GameHighScoreType[] |
154
|
|
|
*/ |
155
|
|
|
public function getGameHighScores(GetGameHighScoresMethod $method): array |
156
|
|
|
{ |
157
|
|
|
return $this->call($method, GameHighScoreType::class . '[]'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param GetStickerSetMethod $method |
162
|
|
|
* |
163
|
|
|
* @throws NormalizationException |
164
|
|
|
* @throws ResponseException |
165
|
|
|
* |
166
|
|
|
* @return StickerSetType |
167
|
|
|
*/ |
168
|
|
|
public function getStickerSet(GetStickerSetMethod $method): StickerSetType |
169
|
|
|
{ |
170
|
|
|
return $this->call($method, StickerSetType::class); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param GetFileMethod $method |
175
|
|
|
* |
176
|
|
|
* @throws ResponseException |
177
|
|
|
* @throws NormalizationException |
178
|
|
|
* |
179
|
|
|
* @return FileType |
180
|
|
|
*/ |
181
|
2 |
|
public function getFile(GetFileMethod $method): FileType |
182
|
|
|
{ |
183
|
2 |
|
return $this->call($method, FileType::class); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|