|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace unreal4u\TelegramAPI\Abstracts; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use unreal4u\TelegramAPI\Interfaces\TelegramMethodDefinitions; |
|
9
|
|
|
use unreal4u\TelegramAPI\InternalFunctionality\TelegramRawData; |
|
10
|
|
|
use unreal4u\TelegramAPI\Telegram\Types\Message; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Contains methods that all Telegram methods should implement |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract class TelegramMethods implements TelegramMethodDefinitions |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Most of the methods will return a Message object on success, so set that as the default. |
|
19
|
|
|
* |
|
20
|
|
|
* This function may however be overwritten if the method uses another object, there are many examples of this, so |
|
21
|
|
|
* just check out the rest of the code. A good place to start is GetUserProfilePhotos or LeaveChat |
|
22
|
|
|
* |
|
23
|
|
|
* @see unreal4u\TelegramAPI\Telegram\Methods\GetUserProfilePhotos |
|
24
|
|
|
* @see unreal4u\TelegramAPI\Telegram\Methods\LeaveChat |
|
25
|
|
|
* |
|
26
|
|
|
* @param TelegramRawData $data |
|
27
|
|
|
* @param LoggerInterface $logger |
|
28
|
|
|
* |
|
29
|
|
|
* @return TelegramTypes |
|
30
|
|
|
*/ |
|
31
|
8 |
|
public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes |
|
32
|
|
|
{ |
|
33
|
8 |
|
return new Message($data->getResult(), $logger); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Before making the actual request this method will be called |
|
38
|
|
|
* |
|
39
|
|
|
* It must be used to json_encode stuff, or do other changes in the internal class representation _before_ sending |
|
40
|
|
|
* it to the Telegram servers |
|
41
|
|
|
* |
|
42
|
|
|
* @return TelegramMethods |
|
43
|
|
|
*/ |
|
44
|
22 |
|
public function performSpecialConditions(): TelegramMethods |
|
45
|
|
|
{ |
|
46
|
22 |
|
if (!empty($this->reply_markup)) { |
|
47
|
1 |
|
$this->reply_markup = json_encode($this->reply_markup); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
22 |
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|