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\Interfaces\AddMethodAliasInterface; |
9
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\AnswerMethodAliasInterface; |
10
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\CreateMethodAliasInterface; |
11
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\DeleteMethodAliasInterface; |
12
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\EditMethodAliasInterface; |
13
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\ForwardMethodAliasInterface; |
14
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\KickMethodAliasInterface; |
15
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\LeaveMethodAliasInterface; |
16
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\MethodInterface; |
17
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\PinMethodAliasInterface; |
18
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\PromoteMethodAliasInterface; |
19
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\RestrictMethodAliasInterface; |
20
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\SendMethodAliasInterface; |
21
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\SetMethodAliasInterface; |
22
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\StopMethodAliasInterface; |
23
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\UnbanMethodAliasInterface; |
24
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\UnpinMethodAliasInterface; |
25
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\UploadMethodAliasInterface; |
26
|
|
|
use TgBotApi\BotApiBase\Type\FileType; |
27
|
|
|
use TgBotApi\BotApiBase\Type\MessageType; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Trait AliasMethodTrait. |
31
|
|
|
*/ |
32
|
|
|
trait AliasMethodTrait |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @param MethodInterface $method |
36
|
|
|
* @param string|null $type |
37
|
|
|
* |
38
|
|
|
* @throws ResponseException |
39
|
|
|
* |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
abstract public function call(MethodInterface $method, string $type = null); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param AddMethodAliasInterface $method |
46
|
|
|
* |
47
|
|
|
* @throws ResponseException |
48
|
|
|
* |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
2 |
|
public function add(AddMethodAliasInterface $method): bool |
52
|
|
|
{ |
53
|
2 |
|
return $this->call($method); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param AnswerMethodAliasInterface $method |
58
|
|
|
* |
59
|
|
|
* @throws ResponseException |
60
|
|
|
* |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
9 |
|
public function answer(AnswerMethodAliasInterface $method): bool |
64
|
|
|
{ |
65
|
9 |
|
return $this->call($method); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param CreateMethodAliasInterface $method |
70
|
|
|
* |
71
|
|
|
* @throws ResponseException |
72
|
|
|
* |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
2 |
|
public function create(CreateMethodAliasInterface $method): bool |
76
|
|
|
{ |
77
|
2 |
|
return $this->call($method); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param DeleteMethodAliasInterface $method |
82
|
|
|
* |
83
|
|
|
* @throws ResponseException |
84
|
|
|
* |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
6 |
|
public function delete(DeleteMethodAliasInterface $method): bool |
88
|
|
|
{ |
89
|
6 |
|
return $this->call($method); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param EditMethodAliasInterface $method |
94
|
|
|
* |
95
|
|
|
* @throws ResponseException |
96
|
|
|
* |
97
|
|
|
* @return MessageType | bool |
98
|
|
|
*/ |
99
|
12 |
|
public function edit(EditMethodAliasInterface $method) |
100
|
|
|
{ |
101
|
12 |
|
return $this->call($method, MessageType::class . '|bool'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param ForwardMethodAliasInterface $method |
106
|
|
|
* |
107
|
|
|
* @throws ResponseException |
108
|
|
|
* |
109
|
|
|
* @return MessageType |
110
|
|
|
*/ |
111
|
2 |
|
public function forward(ForwardMethodAliasInterface $method): MessageType |
112
|
|
|
{ |
113
|
2 |
|
return $this->call($method, MessageType::class); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param KickMethodAliasInterface $method |
118
|
|
|
* |
119
|
|
|
* @throws ResponseException |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
1 |
|
public function kick(KickMethodAliasInterface $method): bool |
124
|
|
|
{ |
125
|
1 |
|
return $this->call($method); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param LeaveMethodAliasInterface $method |
130
|
|
|
* |
131
|
|
|
* @throws ResponseException |
132
|
|
|
* |
133
|
|
|
* @return bool |
134
|
|
|
*/ |
135
|
1 |
|
public function leave(LeaveMethodAliasInterface $method): bool |
136
|
|
|
{ |
137
|
1 |
|
return $this->call($method); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param PinMethodAliasInterface $method |
142
|
|
|
* |
143
|
|
|
* @throws ResponseException |
144
|
|
|
* |
145
|
|
|
* @return bool |
146
|
|
|
*/ |
147
|
1 |
|
public function pin(PinMethodAliasInterface $method): bool |
148
|
|
|
{ |
149
|
1 |
|
return $this->call($method); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param PromoteMethodAliasInterface $method |
154
|
|
|
* |
155
|
|
|
* @throws ResponseException |
156
|
|
|
* |
157
|
|
|
* @return bool |
158
|
|
|
*/ |
159
|
1 |
|
public function promote(PromoteMethodAliasInterface $method): bool |
160
|
|
|
{ |
161
|
1 |
|
return $this->call($method); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param RestrictMethodAliasInterface $method |
166
|
|
|
* |
167
|
|
|
* @throws ResponseException |
168
|
|
|
* |
169
|
|
|
* @return bool |
170
|
|
|
*/ |
171
|
2 |
|
public function restrict(RestrictMethodAliasInterface $method): bool |
172
|
|
|
{ |
173
|
2 |
|
return $this->call($method); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param SendMethodAliasInterface $method |
178
|
|
|
* |
179
|
|
|
* @throws ResponseException |
180
|
|
|
* |
181
|
|
|
* @return MessageType |
182
|
|
|
*/ |
183
|
32 |
|
public function send(SendMethodAliasInterface $method): MessageType |
184
|
|
|
{ |
185
|
32 |
|
return $this->call($method, MessageType::class); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param SetMethodAliasInterface $method |
190
|
|
|
* |
191
|
|
|
* @throws ResponseException |
192
|
|
|
* |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
23 |
|
public function set(SetMethodAliasInterface $method): bool |
196
|
|
|
{ |
197
|
23 |
|
return $this->call($method); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param StopMethodAliasInterface $method |
202
|
|
|
* |
203
|
|
|
* @throws ResponseException |
204
|
|
|
* |
205
|
|
|
* @return bool |
206
|
|
|
*/ |
207
|
2 |
|
public function stop(StopMethodAliasInterface $method): bool |
208
|
|
|
{ |
209
|
2 |
|
return $this->call($method); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param UnbanMethodAliasInterface $method |
214
|
|
|
* |
215
|
|
|
* @throws ResponseException |
216
|
|
|
* |
217
|
|
|
* @return bool |
218
|
|
|
*/ |
219
|
2 |
|
public function unban(UnbanMethodAliasInterface $method): bool |
220
|
|
|
{ |
221
|
2 |
|
return $this->call($method); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param UnpinMethodAliasInterface $method |
226
|
|
|
* |
227
|
|
|
* @throws ResponseException |
228
|
|
|
* |
229
|
|
|
* @return bool |
230
|
|
|
*/ |
231
|
3 |
|
public function unpin(UnpinMethodAliasInterface $method): bool |
232
|
|
|
{ |
233
|
3 |
|
return $this->call($method); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @param UploadMethodAliasInterface $method |
238
|
|
|
* |
239
|
|
|
* @throws ResponseException |
240
|
|
|
* |
241
|
|
|
* @return FileType |
242
|
|
|
*/ |
243
|
1 |
|
public function upload(UploadMethodAliasInterface $method): FileType |
244
|
|
|
{ |
245
|
1 |
|
return $this->call($method, FileType::class); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|