@@ -43,7 +43,8 @@ class QuickBase {
43
43
'errdetail ' => ''
44
44
),
45
45
46
- 'maxErrorRetryAttempts ' => 3
46
+ 'maxErrorRetryAttempts ' => 3 ,
47
+ 'responseAsObject ' => false
47
48
);
48
49
49
50
public function __construct ($ options = array ()){
@@ -61,8 +62,13 @@ final public function api($action, $options = array()){
61
62
->actionRequest ()
62
63
->constructPayload ()
63
64
->transmit ()
65
+ ->checkForAndHandleError ()
64
66
->actionResponse ();
65
67
68
+ if (isset ($ query ->options ['responseAsObject ' ]) && $ query ->options ['responseAsObject ' ]){
69
+ QuickBaseQuery::arr2Obj ($ query ->response );
70
+ }
71
+
66
72
return $ query ->response ;
67
73
}
68
74
@@ -101,6 +107,7 @@ class QuickBaseQuery {
101
107
102
108
public $ parent ;
103
109
public $ action = '' ;
110
+ public $ settings = array ();
104
111
public $ options = array ();
105
112
public $ response = array ();
106
113
@@ -150,6 +157,10 @@ final public function addFlags(){
150
157
$ this ->options ['encoding ' ] = $ this ->settings ['flags ' ]['encoding ' ];
151
158
}
152
159
160
+ if (!isset ($ this ->options ['responseAsObject ' ]) && $ this ->settings ['responseAsObject ' ]){
161
+ $ this ->options ['responseAsObject ' ] = $ this ->settings ['responseAsObject ' ];
162
+ }
163
+
153
164
return $ this ;
154
165
}
155
166
@@ -195,6 +206,12 @@ final public function checkForAndHandleError(){
195
206
->constructPayload ()
196
207
->transmit ();
197
208
}catch (Exception $ newTicketErr ){
209
+ ++$ this ->nErrors ;
210
+
211
+ if ($ this ->nErrors <= $ this ->parent ->settings ['maxErrorRetryAttempts ' ]){
212
+ return $ this ->checkForAndHandleError ();
213
+ }
214
+
198
215
throw $ newTicketErr ;
199
216
}
200
217
}
@@ -286,8 +303,6 @@ final public function transmit(){
286
303
$ this ->xml2Arr ($ xml , $ this ->response );
287
304
288
305
$ this ->cleanXml2Arr ($ this ->response );
289
-
290
- $ this ->checkForAndHandleError ();
291
306
}else {
292
307
$ this ->response = $ body ;
293
308
}
@@ -296,7 +311,27 @@ final public function transmit(){
296
311
}
297
312
298
313
/* Helpers */
299
- final protected static function arr2Xml ($ arr , &$ xml ){
314
+ final public static function arr2Obj (&$ arr , $ return = false ){
315
+ $ obj = new stdClass ;
316
+
317
+ foreach ($ arr as $ key => $ val ){
318
+ if (!empty ($ key )){
319
+ if (is_array ($ val )){
320
+ $ obj ->{$ key } = self ::arr2Obj ($ val , true );
321
+ }else {
322
+ $ obj ->{$ key } = $ val ;
323
+ }
324
+ }
325
+ }
326
+
327
+ if ($ return ){
328
+ return $ obj ;
329
+ }
330
+
331
+ $ arr = $ obj ;
332
+ }
333
+
334
+ final public static function arr2Xml ($ arr , &$ xml ){
300
335
if (is_array ($ arr )){
301
336
foreach ($ arr as $ key => $ value ){
302
337
if ($ key === '$ ' ){
@@ -336,7 +371,7 @@ final protected static function arr2Xml($arr, &$xml){
336
371
}
337
372
}
338
373
339
- final protected static function cleanXml2Arr (&$ arr ){
374
+ final public static function cleanXml2Arr (&$ arr ){
340
375
if (is_array ($ arr )){
341
376
foreach ($ arr as $ key => $ value ){
342
377
if (is_array ($ value ) && count ($ value ) === 1 ){
@@ -377,7 +412,7 @@ final protected static function cleanXml2Arr(&$arr){
377
412
}
378
413
}
379
414
380
- final protected static function parseCURLHeaders (&$ headers ){
415
+ final public static function parseCURLHeaders (&$ headers ){
381
416
$ newHeaders = array ();
382
417
$ headers = explode ("\r\n" , $ headers );
383
418
@@ -390,7 +425,7 @@ final protected static function parseCURLHeaders(&$headers){
390
425
$ headers = $ newHeaders ;
391
426
}
392
427
393
- final protected static function xml2Arr ($ xml , &$ arr ){
428
+ final public static function xml2Arr ($ xml , &$ arr ){
394
429
for ($ xml ->rewind (); $ xml ->valid (); $ xml ->next ()){
395
430
$ key = $ xml ->key ();
396
431
0 commit comments