@@ -17,8 +17,6 @@ class Request
17
17
{
18
18
private static $ telegram ;
19
19
private static $ input ;
20
- private static $ input_raw ;
21
- private static $ server_response ;
22
20
23
21
private static $ methods = array (
24
22
'getMe ' ,
@@ -46,10 +44,10 @@ public static function initialize(Telegram $telegram)
46
44
}
47
45
}
48
46
49
- public static function setInputRaw ($ input_raw )
47
+ public static function setInputRaw ($ input )
50
48
{
51
- if (is_string ($ input_raw )) {
52
- self ::$ input_raw = $ input_raw ;
49
+ if (is_string ($ input )) {
50
+ self ::$ input = $ input ;
53
51
} else {
54
52
throw new TelegramException ("Log input is not a string " );
55
53
}
@@ -63,7 +61,7 @@ public static function getInput()
63
61
self ::setInputRaw (file_get_contents ('php://input ' ));
64
62
}
65
63
self ::log ();
66
- return self ::$ input_raw ;
64
+ return self ::$ input ;
67
65
}
68
66
69
67
@@ -77,7 +75,7 @@ private static function log()
77
75
return false ;
78
76
}
79
77
80
- $ status = file_put_contents ($ path , self ::$ input_raw . "\n" , FILE_APPEND );
78
+ $ status = file_put_contents ($ path , self ::$ input . "\n" , FILE_APPEND );
81
79
82
80
return $ status ;
83
81
}
@@ -109,12 +107,12 @@ public static function generateGeneralFakeServerSesponse($data = null)
109
107
return $ fake_response ;
110
108
}
111
109
112
- public static function executeCurl (i $ action , array $ data )
110
+ public static function executeCurl ($ action , array $ data )
113
111
{
114
112
115
113
$ ch = curl_init ();
116
114
if ($ ch === false ) {
117
- throw new TelegramException ('Curl Failed to initialize ' );
115
+ throw new TelegramException ('Curl failed to initialize ' );
118
116
}
119
117
120
118
$ curlConfig = array (
@@ -136,6 +134,11 @@ public static function executeCurl(i$action, array $data)
136
134
if ($ result === false ) {
137
135
throw new TelegramException (curl_error ($ ch ), curl_errno ($ ch ));
138
136
}
137
+
138
+ if (empty ($ result )) {
139
+ throw new TelegramException ('Empty server response ' );
140
+ }
141
+
139
142
curl_close ($ ch );
140
143
return $ result ;
141
144
}
@@ -153,15 +156,6 @@ public static function send($action, array $data = null)
153
156
154
157
$ result = self ::executeCurl ($ action , $ data );
155
158
156
- if (empty ($ result )) {
157
- $ response ['ok ' ] = 1 ;
158
- $ response ['error_code ' ] = 1 ;
159
- $ response ['description ' ] = 'Empty server response ' ;
160
- $ result =json_encode ($ response );
161
- }
162
- //For the getUpdate method log
163
- //self::setInputRaw($result);
164
-
165
159
$ bot_name = self ::$ telegram ->getBotName ();
166
160
return new ServerResponse (json_decode ($ result , true ), $ bot_name );
167
161
}
@@ -193,7 +187,6 @@ public static function sendMessage(array $data)
193
187
//sendVoice
194
188
public static function sendLocation (array $ data )
195
189
{
196
-
197
190
if (empty ($ data )) {
198
191
throw new TelegramException ('Data is empty! ' );
199
192
}
@@ -221,15 +214,8 @@ public static function getUpdates($data)
221
214
if ($ update = self ::$ telegram ->getCustomUpdate ()) {
222
215
self ::setInputRaw ($ update );
223
216
} else {
224
-
225
217
$ result = self ::executeCurl ('getUpdates ' , $ data );
226
218
227
- if (empty ($ result )) {
228
- $ response ['ok ' ] = 1 ;
229
- $ response ['error_code ' ] = 1 ;
230
- $ response ['description ' ] = 'Empty server response ' ;
231
- $ result =json_encode ($ response );
232
- }
233
219
self ::setInputRaw ($ result );
234
220
235
221
}
0 commit comments