1 | <?php |
||
18 | abstract class TelegramMethods implements TelegramMethodDefinitions |
||
19 | { |
||
20 | /** |
||
21 | * @var TelegramResponse |
||
22 | */ |
||
23 | protected $response; |
||
24 | |||
25 | /** |
||
26 | * Most of the methods will return a Message object on success, so set that as the default. |
||
27 | * |
||
28 | * This function may however be overwritten if the method uses another object, there are many examples of this, so |
||
29 | * just check out the rest of the code. A good place to start is GetUserProfilePhotos or LeaveChat |
||
30 | * |
||
31 | * @see \unreal4u\TelegramAPI\Telegram\Methods\GetUserProfilePhotos |
||
32 | * @see \unreal4u\TelegramAPI\Telegram\Methods\LeaveChat |
||
33 | * |
||
34 | * @param TelegramResponse $data |
||
35 | * @param LoggerInterface $logger |
||
36 | * |
||
37 | * @return TelegramTypes |
||
38 | */ |
||
39 | 9 | public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes |
|
43 | |||
44 | /** |
||
45 | * Before making the actual request this method will be called |
||
46 | * |
||
47 | * It must be used to json_encode stuff, or do other changes in the internal class representation _before_ sending |
||
48 | * it to the Telegram servers |
||
49 | * |
||
50 | * @return TelegramMethods |
||
51 | */ |
||
52 | 32 | public function performSpecialConditions(): TelegramMethods |
|
60 | |||
61 | /** |
||
62 | * Exports the class to an array in order to send it to the Telegram servers without extra fields that we don't need |
||
63 | * |
||
64 | * @return array |
||
65 | * @throws MissingMandatoryField |
||
66 | */ |
||
67 | 38 | final public function export(): array |
|
92 | |||
93 | /** |
||
94 | * Will resolve the dependency of a mandatory inline_message_id OR a chat_id + message_id |
||
95 | * |
||
96 | * NOTE: This will use pass by reference instead of copy on write as the use-case for this functions allows this |
||
97 | * |
||
98 | * @param array $return |
||
99 | * @return array |
||
100 | */ |
||
101 | 4 | final protected function mandatoryUserOrInlineMessageId(array &$return): array |
|
115 | |||
116 | /** |
||
117 | * ReplyMarkup fields require a bit of work before sending them |
||
118 | * |
||
119 | * This happens because reply markup are a type thus they don't have an export mechanism to do the job |
||
120 | * |
||
121 | * @param TelegramTypes $replyMarkup |
||
122 | * @return TelegramTypes |
||
123 | */ |
||
124 | 1 | final private function formatReplyMarkup(TelegramTypes $replyMarkup): TelegramTypes |
|
134 | |||
135 | 1 | final private function getArrayFromKeyboard(array $keyboardArray): array |
|
157 | |||
158 | /** |
||
159 | * Does the definitive export of those fields in a reply markup item that are filled in |
||
160 | * |
||
161 | * @param TelegramTypes $markupItem |
||
162 | * @return array |
||
163 | */ |
||
164 | final private function exportReplyMarkupItem(TelegramTypes $markupItem): array |
||
176 | } |
||
177 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: