@@ -22,35 +22,52 @@ class ServerResponse extends Entity
22
22
protected $ error_code ;
23
23
protected $ description ;
24
24
25
+
25
26
public function __construct (array $ data , $ bot_name )
26
27
{
27
-
28
28
if (isset ($ data ['ok ' ]) & isset ($ data ['result ' ])) {
29
- if ($ data ['ok ' ] & is_array ($ data ['result ' ])) {
30
- //Response from sendMessage set
31
- $ this ->ok = $ data ['ok ' ];
32
- $ this ->result = new Message ($ data ['result ' ], $ bot_name );
33
- $ this ->error_code = null ;
34
- $ this ->description = null ;
29
+ if (is_array ($ data ['result ' ])) {
30
+ if ($ data ['ok ' ] & !$ this ->isAssoc ($ data ['result ' ])) {
31
+ //update id
32
+ $ this ->ok = $ data ['ok ' ];
33
+ //$this->result =[];
34
+ foreach ($ data ['result ' ] as $ update ) {
35
+ $ this ->result [] = new Update ($ update , $ bot_name );
36
+ }
37
+ $ this ->error_code = null ;
38
+ $ this ->description = null ;
39
+
40
+ } elseif ($ data ['ok ' ] & $ this ->isAssoc ($ data ['result ' ])) {
41
+ //Response from sendMessage set
42
+ $ this ->ok = $ data ['ok ' ];
43
+ $ this ->result = new Message ($ data ['result ' ], $ bot_name );
44
+ $ this ->error_code = null ;
45
+ $ this ->description = null ;
46
+ }
47
+
35
48
36
- } elseif ($ data ['ok ' ] & $ data ['result ' ] == true ) {
37
- //Response from setWebhook set
38
- $ this ->ok = $ data ['ok ' ];
39
- $ this ->result = true ;
40
- $ this ->error_code = null ;
41
49
42
- if (isset ($ data ['description ' ])) {
43
- $ this ->description = $ data ['description ' ];
50
+ } else {
51
+ if ($ data ['ok ' ] & $ data ['result ' ] == true ) {
52
+ //Response from setWebhook set
53
+ $ this ->ok = $ data ['ok ' ];
54
+ $ this ->result = true ;
55
+ $ this ->error_code = null ;
56
+
57
+ if (isset ($ data ['description ' ])) {
58
+ $ this ->description = $ data ['description ' ];
59
+ } else {
60
+ $ this ->description = '' ;
61
+ }
44
62
} else {
45
- $ this ->description = '' ;
63
+ $ this ->ok = false ;
64
+ $ this ->result = null ;
65
+ $ this ->error_code = $ data ['error_code ' ];
66
+ $ this ->description = $ data ['description ' ];
46
67
}
47
68
48
- } else {
49
- $ this ->ok = false ;
50
- $ this ->result = null ;
51
- $ this ->error_code = $ data ['error_code ' ];
52
- $ this ->description = $ data ['description ' ];
53
69
}
70
+
54
71
} else {
55
72
//webHook not set
56
73
$ this ->ok = false ;
@@ -77,6 +94,11 @@ public function __construct(array $data, $bot_name)
77
94
}
78
95
}
79
96
97
+ //must be an array
98
+ protected function isAssoc (array $ array )
99
+ {
100
+ return (bool )count (array_filter (array_keys ($ array ), 'is_string ' ));
101
+ }
80
102
public function isOk ()
81
103
{
82
104
return $ this ->ok ;
0 commit comments