1 | <?php |
||
9 | class TelegramResponse |
||
10 | { |
||
11 | /** |
||
12 | * Nothing is done so far with this, but it's always a good idea to have the original around |
||
13 | * @var string |
||
14 | */ |
||
15 | private $rawData = ''; |
||
16 | |||
17 | /** |
||
18 | * The actual representation of the decoded data |
||
19 | * @var array |
||
20 | */ |
||
21 | private $decodedData = []; |
||
22 | |||
23 | /** |
||
24 | * The headers sent with the response. |
||
25 | * @var array |
||
26 | */ |
||
27 | private $headers = []; |
||
28 | |||
29 | /** |
||
30 | * @var \Exception |
||
31 | */ |
||
32 | private $exception = null; |
||
33 | |||
34 | /** |
||
35 | * Marks the actual response as an error |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $isError = false; |
||
39 | |||
40 | public function __construct(string $rawData, array $headers = [], \Exception $e = null) |
||
50 | |||
51 | /** |
||
52 | * Will return true if the request was an unsuccessful one, false otherwise |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function isError(): bool |
||
59 | |||
60 | /** |
||
61 | * Fills in the raw data |
||
62 | * |
||
63 | * @param string $rawData |
||
64 | * @return TelegramResponse |
||
65 | */ |
||
66 | public function fillRawData(string $rawData): TelegramResponse |
||
73 | |||
74 | /** |
||
75 | * To quickly find out what type of request we are dealing with |
||
76 | * |
||
77 | * Unused so far |
||
78 | * |
||
79 | * @return string |
||
80 | * @throws InvalidResultType |
||
81 | */ |
||
82 | public function getTypeOfResult(): string |
||
95 | |||
96 | /** |
||
97 | * Most of the requests Telegram sends, come as an array, so send the response back as an array by default |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public function getResult(): array |
||
105 | |||
106 | /** |
||
107 | * Hack: for some requests Telegram sends back an array, integer, string or a boolean value, convert it to boolean |
||
108 | * here |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function getResultBoolean(): bool |
||
115 | |||
116 | /** |
||
117 | * Hack: for some requests Telegram send back an array, integer, string or a boolean value, convert it to int here |
||
118 | * @return int |
||
119 | */ |
||
120 | public function getResultInt(): int |
||
124 | |||
125 | /** |
||
126 | * Hack: for some requests Telegram send back an array, integer, string or a boolean value, convert it to string |
||
127 | * here |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getResultString(): string |
||
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | public function getRawData() |
||
142 | |||
143 | /** |
||
144 | * @return array |
||
145 | */ |
||
146 | public function getHeaders(): array |
||
150 | |||
151 | /** |
||
152 | * Returns the raw error data |
||
153 | * @return array |
||
154 | */ |
||
155 | public function getErrorData(): array |
||
159 | |||
160 | /** |
||
161 | * @return \Exception |
||
162 | */ |
||
163 | public function getException(): \Exception |
||
167 | } |
||
168 |