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