1 | <?php |
||
26 | abstract class Entity |
||
27 | { |
||
28 | /** |
||
29 | * Entity constructor. |
||
30 | * |
||
31 | * @todo Get rid of the $bot_name, it shouldn't be here! |
||
32 | * |
||
33 | * @param array $data |
||
34 | * @param string $bot_name |
||
35 | * |
||
36 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
37 | 1 | */ |
|
38 | public function __construct($data, $bot_name = '') |
||
39 | 1 | { |
|
40 | 1 | //Make sure we're not raw_data inception-ing |
|
41 | if (array_key_exists('raw_data', $data)) { |
||
42 | 1 | if ($data['raw_data'] === null) { |
|
43 | unset($data['raw_data']); |
||
44 | } |
||
45 | } else { |
||
46 | $data['raw_data'] = $data; |
||
47 | } |
||
48 | |||
49 | $data['bot_name'] = $bot_name; |
||
50 | $this->assignMemberVariables($data); |
||
51 | 1 | $this->validate(); |
|
52 | } |
||
53 | 1 | ||
54 | /** |
||
55 | * Perform to json |
||
56 | * |
||
57 | 1 | * @return string |
|
58 | 1 | */ |
|
59 | public function toJson() |
||
63 | 1 | ||
64 | 1 | /** |
|
65 | 1 | * Perform to string |
|
66 | * |
||
67 | * @return string |
||
68 | 1 | */ |
|
69 | 1 | public function __toString() |
|
73 | |||
74 | /** |
||
75 | * Helper to set member variables |
||
76 | * |
||
77 | * @param array $data |
||
78 | */ |
||
79 | protected function assignMemberVariables(array $data) |
||
85 | |||
86 | /** |
||
87 | * Get the list of the properties that are themselves Entities |
||
88 | * |
||
89 | * @return array |
||
90 | 1 | */ |
|
91 | 1 | protected function subEntities() |
|
95 | |||
96 | 1 | /** |
|
97 | * Perform any special entity validation |
||
98 | * |
||
99 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
100 | */ |
||
101 | protected function validate() |
||
104 | |||
105 | /** |
||
106 | * Get a property from the current Entity |
||
107 | * |
||
108 | 1 | * @param mixed $property |
|
109 | 1 | * @param mixed $default |
|
110 | 1 | * |
|
111 | 1 | * @return mixed |
|
112 | */ |
||
113 | 1 | public function getProperty($property, $default = null) |
|
121 | |||
122 | /** |
||
123 | * Return the variable for the called getter or magically set properties dynamically. |
||
124 | * |
||
125 | * @param $method |
||
126 | * @param $args |
||
127 | * |
||
128 | * @return mixed|null |
||
129 | */ |
||
130 | public function __call($method, $args) |
||
160 | |||
161 | /** |
||
162 | * Return an array of nice objects from an array of object arrays |
||
163 | * |
||
164 | * This method is used to generate pretty object arrays |
||
165 | * mainly for PhotoSize and Entities object arrays. |
||
166 | * |
||
167 | * @param string $class |
||
168 | * @param string $property |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | protected function makePrettyObjectArray($class, $property) |
||
190 | |||
191 | /** |
||
192 | * Escape markdown special characters |
||
193 | * |
||
194 | * @param string $string |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | public function escapeMarkdown($string) |
||
206 | |||
207 | /** |
||
208 | * Try to mention the user |
||
209 | * |
||
210 | * Mention the user with the username otherwise print first and last name |
||
211 | * if the $escape_markdown argument is true special characters are escaped from the output |
||
212 | * |
||
213 | * @param bool $escape_markdown |
||
214 | * |
||
215 | * @return string|null |
||
216 | */ |
||
217 | public function tryMention($escape_markdown = false) |
||
243 | } |
||
244 |