1 | <?php |
||
9 | class TelegramRawData |
||
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 | * @var \Exception |
||
25 | */ |
||
26 | private $exception = null; |
||
27 | |||
28 | /** |
||
29 | * Marks the actual response as an error |
||
30 | * @var bool |
||
31 | */ |
||
32 | private $isError = false; |
||
33 | |||
34 | 35 | public function __construct(string $rawData = '', \Exception $e = null) |
|
45 | |||
46 | /** |
||
47 | * Will return true if the request was an unsuccessful one, false otherwise |
||
48 | * @return bool |
||
49 | */ |
||
50 | 23 | public function isError(): bool |
|
54 | |||
55 | /** |
||
56 | * Fills in the raw data |
||
57 | * |
||
58 | * @param string $rawData |
||
59 | * @return TelegramRawData |
||
60 | */ |
||
61 | 35 | public function fillRawData(string $rawData): TelegramRawData |
|
68 | |||
69 | /** |
||
70 | * To quickly find out what type of request we are dealing with |
||
71 | * |
||
72 | * Unused so far |
||
73 | * |
||
74 | * @return string |
||
75 | * @throws InvalidResultType |
||
76 | */ |
||
77 | 8 | public function getTypeOfResult(): string |
|
90 | |||
91 | /** |
||
92 | * Most of the requests Telegram sends, come as an array, so send the response back as an array by default |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | 21 | public function getResult(): array |
|
100 | |||
101 | /** |
||
102 | * Hack: for some requests Telegram sends back an array, integer, string or a boolean value, convert it to boolean |
||
103 | * here |
||
104 | * @return bool |
||
105 | */ |
||
106 | 5 | public function getResultBoolean(): bool |
|
110 | |||
111 | /** |
||
112 | * Hack: for some requests Telegram send back an array, integer, string or a boolean value, convert it to int here |
||
113 | * @return int |
||
114 | */ |
||
115 | 1 | public function getResultInt(): int |
|
119 | |||
120 | /** |
||
121 | * Hack: for some requests Telegram send back an array, integer, string or a boolean value, convert it to string |
||
122 | * here |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getResultString(): string |
||
129 | |||
130 | /** |
||
131 | * Returns the raw error data |
||
132 | * @return array |
||
133 | */ |
||
134 | public function getErrorData(): array |
||
138 | |||
139 | /** |
||
140 | * @return \Exception |
||
141 | */ |
||
142 | public function getException(): \Exception |
||
146 | } |
||
147 |