@@ -249,11 +249,10 @@ class ApiClient extends \Ease\Brick
249
249
protected $ ignoreNotFound = false ;
250
250
251
251
/**
252
- * Array of errors caused by last request
253
- * @var array
252
+ * Token handling object live here
253
+ * @var Token
254
254
*/
255
- private $ errors = [];
256
- protected $ tokener = null ;
255
+ protected $ tokener = null ;
257
256
258
257
/**
259
258
* Class for read only interaction with IPEX.
@@ -297,24 +296,6 @@ public function setUp($options = [])
297
296
$ this ->updateApiURL ();
298
297
}
299
298
300
- /**
301
- * Set up one of properties
302
- *
303
- * @param array $options array of given properties
304
- * @param string $name name of property to process
305
- * @param string $constant load default property value from constant
306
- */
307
- public function setupProperty ($ options , $ name , $ constant = null )
308
- {
309
- if (isset ($ options [$ name ])) {
310
- $ this ->$ name = $ options [$ name ];
311
- } else {
312
- if (is_null ($ this ->$ name ) && !empty ($ constant ) && defined ($ constant )) {
313
- $ this ->$ name = constant ($ constant );
314
- }
315
- }
316
- }
317
-
318
299
/**
319
300
* Inicializace CURL
320
301
*/
@@ -352,6 +333,7 @@ public function processInit($init)
352
333
* Set section for communication
353
334
*
354
335
* @param string $section section pathName to use
336
+ *
355
337
* @return boolean section switching status
356
338
*/
357
339
public function setSection ($ section )
@@ -371,67 +353,16 @@ public function getSection()
371
353
return $ this ->section ;
372
354
}
373
355
374
- /**
375
- * Převede rekurzivně Objekt na pole.
376
- *
377
- * @param object|array $object
378
- *
379
- * @return array
380
- */
381
- public static function object2array ($ object )
382
- {
383
- $ result = null ;
384
- if (is_object ($ object )) {
385
- $ objectData = get_object_vars ($ object );
386
- if (is_array ($ objectData ) && count ($ objectData )) {
387
- $ result = array_map ('self::object2array ' , $ objectData );
388
- }
389
- } else {
390
- if (is_array ($ object )) {
391
- foreach ($ object as $ item => $ value ) {
392
- $ result [$ item ] = self ::object2array ($ value );
393
- }
394
- } else {
395
- $ result = $ object ;
396
- }
397
- }
398
-
399
- return $ result ;
400
- }
401
-
402
- /**
403
- * Převede rekurzivně v poli všechny objekty na jejich identifikátory.
404
- *
405
- * @param object|array $object
406
- *
407
- * @return array
408
- */
409
- public static function objectToID ($ object )
410
- {
411
- $ resultID = null ;
412
- if (is_object ($ object )) {
413
- $ resultID = $ object ->__toString ();
414
- } else {
415
- if (is_array ($ object )) {
416
- foreach ($ object as $ item => $ value ) {
417
- $ resultID [$ item ] = self ::objectToID ($ value );
418
- }
419
- } else { //String
420
- $ resultID = $ object ;
421
- }
422
- }
423
-
424
- return $ resultID ;
425
- }
426
-
427
356
/**
428
357
* Připraví data pro odeslání do FlexiBee
429
358
*
430
359
* @param string $data
360
+ *
361
+ * @return string Data strored
431
362
*/
432
363
public function setPostFields ($ data )
433
364
{
434
- $ this ->postFields = $ data ;
365
+ return $ this ->postFields = $ data ;
435
366
}
436
367
437
368
/**
@@ -468,40 +399,24 @@ public function sectionUrlWithSuffix($urlSuffix)
468
399
return $ sectionUrl ;
469
400
}
470
401
471
- /**
472
- * Add params to url
473
- *
474
- * @param string $url originall url
475
- * @param array $params value to add
476
- * @param boolean $override replace already existing values ?
477
- *
478
- * @return string url with parameters added
479
- */
480
- public function addUrlParams ($ url , $ params , $ override = false )
481
- {
482
- $ urlParts = parse_url ($ url );
483
- $ urlFinal = '' ;
484
- if (array_key_exists ('scheme ' , $ urlParts )) {
485
- $ urlFinal .= $ urlParts ['scheme ' ].':// ' .$ urlParts ['host ' ];
486
- }
487
- if (array_key_exists ('path ' , $ urlParts )) {
488
- $ urlFinal .= $ urlParts ['path ' ];
489
- }
490
- if (array_key_exists ('query ' , $ urlParts )) {
491
- parse_str ($ urlParts ['query ' ], $ queryUrlParams );
492
- $ urlParams = $ override ? array_merge ($ params , $ queryUrlParams ) : array_merge ($ queryUrlParams ,
493
- $ params );
494
- } else {
495
- $ urlParams = $ params ;
496
- }
497
- if (!empty ($ urlParams ) && is_array ($ urlParams )) {
498
- $ urlFinal .= '? ' .http_build_query ($ urlParams );
402
+
403
+ /**
404
+ * Add UrlParams to Requests URL
405
+ *
406
+ * @param array $urlParams
407
+ *
408
+ * @return array all urlParams
409
+ */
410
+ public function setUrlParams ($ urlParams ){
411
+ if (is_array ($ this ->urlParams )){
412
+ $ this ->urlParams = array_merge ($ this ->urlParams , $ urlParams );
499
413
} else {
500
- $ urlFinal .= ' ? ' . $ urlParams ;
414
+ $ this -> urlParams = $ urlParams ;
501
415
}
502
- return $ urlFinal ;
416
+ return $ this -> urlParams ;
503
417
}
504
418
419
+
505
420
/**
506
421
* Update $this->apiURL
507
422
*/
@@ -526,13 +441,13 @@ public function requestData($urlSuffix = null, $method = 'GET',
526
441
527
442
if (preg_match ('/^http/ ' , $ urlSuffix )) {
528
443
$ url = $ urlSuffix ;
529
- } elseif ($ urlSuffix [0 ] == '/ ' ) {
444
+ } elseif (strlen ( $ urlSuffix) && ( $ urlSuffix [0 ] == '/ ' ) ) {
530
445
$ url = $ this ->url .$ urlSuffix ;
531
446
} else {
532
447
$ url = $ this ->sectionUrlWithSuffix ($ urlSuffix );
533
448
}
534
449
535
- $ responseCode = $ this ->doCurlRequest ($ url , $ method , $ format );
450
+ $ responseCode = $ this ->doCurlRequest ( \ Ease \Shared:: addUrlParams ( $ url, $ this -> urlParams ) , $ method , $ format );
536
451
537
452
return strlen ($ this ->lastCurlResponse ) ? $ this ->parseResponse ($ this ->rawResponseToArray ($ this ->lastCurlResponse ,
538
453
$ this ->responseMimeType ), $ responseCode ) : null ;
@@ -622,10 +537,10 @@ public function parseError(array $responseDecoded)
622
537
/**
623
538
* Vykonej HTTP požadavek
624
539
*
625
- * @link https://www.ipex.eu/api/dokumentace/ref/urls/ Sestavování URL
626
540
* @param string $url URL požadavku
627
541
* @param string $method HTTP Method GET|POST|PUT|OPTIONS|DELETE
628
542
* @param string $format požadovaný formát komunikace
543
+ *
629
544
* @return int HTTP Response CODE
630
545
*/
631
546
public function doCurlRequest ($ url , $ method , $ format = null )
@@ -683,34 +598,15 @@ public function doCurlRequest($url, $method, $format = null)
683
598
}
684
599
685
600
/**
686
- * Convert XML to array.
687
- *
688
- * @param string $xml
689
- *
690
- * @return array
601
+ * Load Data Row from IPEX
602
+ *
603
+ * @param string $key what we want to get
604
+ *
605
+ * @return int loaded columns count
691
606
*/
692
- public static function xml2array ($ xml )
693
- {
694
- $ arr = [];
695
-
696
- if (is_string ($ xml )) {
697
- $ xml = simplexml_load_string ($ xml );
698
- }
699
-
700
- foreach ($ xml ->children () as $ r ) {
701
- if (count ($ r ->children ()) == 0 ) {
702
- $ arr [$ r ->getName ()] = strval ($ r );
703
- } else {
704
- $ arr [$ r ->getName ()][] = self ::xml2array ($ r );
705
- }
706
- }
707
-
708
- return $ arr ;
709
- }
710
-
711
607
public function loadFromIPEX ($ key )
712
608
{
713
- return $ this ->takeData ($ this ->requestData (is_array ($ key ) ? $ this -> addUrlParams (null ,
609
+ return $ this ->takeData ($ this ->requestData (is_array ($ key ) ? \ Ease \Shared:: addUrlParams (null ,
714
610
$ key ) : $ key ));
715
611
}
716
612
@@ -719,6 +615,7 @@ public function loadFromIPEX($key)
719
615
*
720
616
* @param array $resultData
721
617
* @param string $url URL
618
+ *
722
619
* @return boolean Log save success
723
620
*/
724
621
public function logResult ($ resultData = null , $ url = null )
0 commit comments