@@ -43,7 +43,8 @@ class QuickBase {
4343 'errdetail ' => ''
4444 ),
4545
46- 'maxErrorRetryAttempts ' => 3
46+ 'maxErrorRetryAttempts ' => 3 ,
47+ 'responseAsObject ' => false
4748 );
4849
4950 public function __construct ($ options = array ()){
@@ -61,8 +62,13 @@ final public function api($action, $options = array()){
6162 ->actionRequest ()
6263 ->constructPayload ()
6364 ->transmit ()
65+ ->checkForAndHandleError ()
6466 ->actionResponse ();
6567
68+ if (isset ($ query ->options ['responseAsObject ' ]) && $ query ->options ['responseAsObject ' ]){
69+ QuickBaseQuery::arr2Obj ($ query ->response );
70+ }
71+
6672 return $ query ->response ;
6773 }
6874
@@ -101,6 +107,7 @@ class QuickBaseQuery {
101107
102108 public $ parent ;
103109 public $ action = '' ;
110+ public $ settings = array ();
104111 public $ options = array ();
105112 public $ response = array ();
106113
@@ -150,6 +157,10 @@ final public function addFlags(){
150157 $ this ->options ['encoding ' ] = $ this ->settings ['flags ' ]['encoding ' ];
151158 }
152159
160+ if (!isset ($ this ->options ['responseAsObject ' ]) && $ this ->settings ['responseAsObject ' ]){
161+ $ this ->options ['responseAsObject ' ] = $ this ->settings ['responseAsObject ' ];
162+ }
163+
153164 return $ this ;
154165 }
155166
@@ -195,6 +206,12 @@ final public function checkForAndHandleError(){
195206 ->constructPayload ()
196207 ->transmit ();
197208 }catch (Exception $ newTicketErr ){
209+ ++$ this ->nErrors ;
210+
211+ if ($ this ->nErrors <= $ this ->parent ->settings ['maxErrorRetryAttempts ' ]){
212+ return $ this ->checkForAndHandleError ();
213+ }
214+
198215 throw $ newTicketErr ;
199216 }
200217 }
@@ -286,8 +303,6 @@ final public function transmit(){
286303 $ this ->xml2Arr ($ xml , $ this ->response );
287304
288305 $ this ->cleanXml2Arr ($ this ->response );
289-
290- $ this ->checkForAndHandleError ();
291306 }else {
292307 $ this ->response = $ body ;
293308 }
@@ -296,7 +311,27 @@ final public function transmit(){
296311 }
297312
298313 /* 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 ){
300335 if (is_array ($ arr )){
301336 foreach ($ arr as $ key => $ value ){
302337 if ($ key === '$ ' ){
@@ -336,7 +371,7 @@ final protected static function arr2Xml($arr, &$xml){
336371 }
337372 }
338373
339- final protected static function cleanXml2Arr (&$ arr ){
374+ final public static function cleanXml2Arr (&$ arr ){
340375 if (is_array ($ arr )){
341376 foreach ($ arr as $ key => $ value ){
342377 if (is_array ($ value ) && count ($ value ) === 1 ){
@@ -377,7 +412,7 @@ final protected static function cleanXml2Arr(&$arr){
377412 }
378413 }
379414
380- final protected static function parseCURLHeaders (&$ headers ){
415+ final public static function parseCURLHeaders (&$ headers ){
381416 $ newHeaders = array ();
382417 $ headers = explode ("\r\n" , $ headers );
383418
@@ -390,7 +425,7 @@ final protected static function parseCURLHeaders(&$headers){
390425 $ headers = $ newHeaders ;
391426 }
392427
393- final protected static function xml2Arr ($ xml , &$ arr ){
428+ final public static function xml2Arr ($ xml , &$ arr ){
394429 for ($ xml ->rewind (); $ xml ->valid (); $ xml ->next ()){
395430 $ key = $ xml ->key ();
396431
0 commit comments