Test Failed
Push — master ( 2514b0...1bd162 )
by Vítězslav
02:52
created

FlexiBeeRO::rawJsonToArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 4.944

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 14
ccs 2
cts 5
cp 0.4
crap 4.944
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * FlexiPeeHP - Read Only Access to FlexiBee class.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015-2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Základní třída pro čtení z FlexiBee
13
 *
14
 * @url https://demo.flexibee.eu/devdoc/
15
 */
16
class FlexiBeeRO extends \Ease\Brick
17
{
18
    /**
19
     * Where to get JSON files with evidence stricture etc.
20
     * @var string
21
     */
22
    public static $infoDir = __DIR__.'/../../static';
23
24
    /**
25
     * Version of FlexiPeeHP library
26
     *
27
     * @var string
28
     */
29
    public static $libVersion = '1.4.2.3';
30
31
    /**
32
     * Základní namespace pro komunikaci s FlexiBee.
33
     * Basic namespace for communication with FlexiBee
34
     *
35
     * @var string Jmený prostor datového bloku odpovědi
36
     */
37
    public $nameSpace = 'winstrom';
38
39
    /**
40
     * URL of object data in FlexiBee
41
     * @var string url
42
     */
43
    public $apiURL = null;
44
45
    /**
46
     * Datový blok v poli odpovědi.
47
     * Data block in response field.
48
     *
49
     * @var string
50
     */
51
    public $resultField = 'results';
52
53
    /**
54
     * Verze protokolu použitého pro komunikaci.
55
     * Communication protocol version used.
56
     *
57
     * @var string Verze použitého API
58
     */
59
    public $protoVersion = '1.0';
60
61
    /**
62
     * Evidence užitá objektem.
63
     * Evidence used by object
64
     *
65
     * @link https://demo.flexibee.eu/c/demo/evidence-list Přehled evidencí
66
     * @var string
67
     */
68
    public $evidence = null;
69
70
    /**
71
     * Výchozí formát pro komunikaci.
72
     * Default communication format.
73
     *
74
     * @link https://www.flexibee.eu/api/dokumentace/ref/format-types Přehled možných formátů
75
     *
76
     * @var string json|xml|...
77
     */
78
    public $format = 'json';
79
80
    /**
81
     * formát příchozí odpovědi
82
     * response format
83
     *
84
     * @link https://www.flexibee.eu/api/dokumentace/ref/format-types Přehled možných formátů
85
     *
86
     * @var string json|xml|...
87
     */
88
    public $responseFormat = 'json';
89
90
    /**
91
     * Curl Handle.
92
     *
93
     * @var resource
94
     */
95
    public $curl = null;
96
97
    /**
98
     * @link https://demo.flexibee.eu/devdoc/company-identifier Identifikátor firmy
99
     * @var string
100
     */
101
    public $company = null;
102
103
    /**
104
     * Server[:port]
105
     * @var string
106
     */
107
    public $url = null;
108
109
    /**
110
     * REST API Username
111
     * @var string
112
     */
113
    public $user = null;
114
115
    /**
116
     * REST API Password
117
     * @var string
118
     */
119
    public $password = null;
120
121
    /**
122
     * @var array Pole HTTP hlaviček odesílaných s každým požadavkem
123
     */
124
    public $defaultHttpHeaders = ['User-Agent' => 'FlexiPeeHP'];
125
126
    /**
127
     * Default additional request url parameters after question mark
128
     *
129
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls   Common params
130
     * @link https://www.flexibee.eu/api/dokumentace/ref/paging Paging params
131
     * @var array
132
     */
133
    public $defaultUrlParams = ['limit' => 0];
134
135
    /**
136
     * Identifikační řetězec.
137
     *
138
     * @var string
139
     */
140
    public $init = null;
141
142
    /**
143
     * Sloupeček s názvem.
144
     *
145
     * @var string
146
     */
147
    public $nameColumn = 'nazev';
148
149
    /**
150
     * Sloupeček obsahující datum vložení záznamu do shopu.
151
     *
152
     * @var string
153
     */
154
    public $myCreateColumn = 'false';
155
156
    /**
157
     * Slopecek obsahujici datum poslení modifikace záznamu do shopu.
158
     *
159
     * @var string
160
     */
161
    public $myLastModifiedColumn = 'lastUpdate';
162
163
    /**
164
     * Klíčový idendifikátor záznamu.
165
     *
166
     * @var string
167
     */
168
    public $fbKeyColumn = 'id';
169
170
    /**
171
     * Informace o posledním HTTP requestu.
172
     *
173
     * @var *
174
     */
175
    public $curlInfo;
176
177
    /**
178
     * Informace o poslední HTTP chybě.
179
     *
180
     * @var string
181
     */
182
    public $lastCurlError = null;
183
184
    /**
185
     * Used codes storage.
186
     *
187
     * @var array
188
     */
189
    public $codes = null;
190
191
    /**
192
     * Last Inserted ID.
193
     *
194
     * @var int
195
     */
196
    public $lastInsertedID = null;
197
198
    /**
199
     * Default Line Prefix.
200
     *
201
     * @var string
202
     */
203
    public $prefix = '/c/';
204
205
    /**
206
     * Raw Content of last curl response
207
     *
208
     * @var string
209
     */
210
    public $lastCurlResponse;
211
212
    /**
213
     * HTTP Response code of last request
214
     *
215
     * @var int
216
     */
217
    public $lastResponseCode = null;
218
219
    /**
220
     * Body data  for next curl POST operation
221
     *
222
     * @var string
223
     */
224
    protected $postFields = null;
225
226
    /**
227
     * Last operation result data or message(s)
228
     *
229
     * @var array
230
     */
231
    public $lastResult = null;
232
233
    /**
234
     * Number from  @rowCount in response
235
     * @var int
236
     */
237
    public $rowCount = null;
238
239
    /**
240
     * Number from  @globalVersion
241
     * @var int
242
     */
243
    public $globalVersion = null;
244
245
    /**
246
     * @link https://www.flexibee.eu/api/dokumentace/ref/zamykani-odemykani/
247
     * @var string filter query
248
     */
249
    public $filter;
250
251
    /**
252
     * @link https://demo.flexibee.eu/devdoc/actions Provádění akcí
253
     * @var string
254
     */
255
    protected $action;
256
257
    /**
258
     * Pole akcí které podporuje ta která evidence
259
     * @link https://demo.flexibee.eu/c/demo/faktura-vydana/actions.json Např. Akce faktury
260
     * @var array
261
     */
262
    public $actionsAvailable = null;
263
264
    /**
265
     * Parmetry pro URL
266
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Všechny podporované parametry
267
     * @var array
268
     */
269
    public $urlParams = [
270
        'idUcetniObdobi',
271
        'dry-run',
272
        'fail-on-warning',
273
        'report-name',
274
        'report-lang',
275
        'report-sign',
276
        'detail', //See: https://www.flexibee.eu/api/dokumentace/ref/detail-levels
277
        'mode',
278
        'limit',
279
        'start',
280
        'order',
281
        'sort',
282
        'add-row-count',
283
        'relations',
284
        'includes',
285
        'use-ext-id',
286
        'use-internal-id',
287
        'stitky-as-ids',
288
        'only-ext-ids',
289
        'no-ext-ids',
290
        'no-ids',
291
        'code-as-id',
292
        'no-http-errors',
293
        'export-settings',
294
        'as-gui',
295
        'code-in-response',
296
        'add-global-version',
297
        'encoding',
298
        'delimeter',
299
        'format',
300
        'auth',
301
        'skupina-stitku',
302
        'dir',
303
        'relations',
304
        'relations',
305
        'xpath', // See: https://www.flexibee.eu/api/dokumentace/ref/xpath/
306
        'dry-run', // See: https://www.flexibee.eu/api/dokumentace/ref/dry-run/
307
        'inDesktopApp' // Note: Undocumented function (html only)
308
    ];
309
310
    /**
311
     * Save 404 results to log ?
312
     * @var boolean
313
     */
314
    protected $ignoreNotFound = false;
315
316
    /**
317
     * Array of errors caused by last request
318
     * @var array
319
     */
320
    private $errors = [];
321
322
    /**
323
     * List of Error500 reports sent
324
     * @var array
325
     */
326
    private $reports = [];
327
328
    /**
329
     * Send Error500 Report to
330
     * @var string email address
331
     */
332
    public $reportRecipient = '[email protected]';
333
334
    /**
335
     * Class for read only interaction with FlexiBee.
336
     *
337
     * @param mixed $init default record id or initial data
338
     * @param array $options Connection settings override
339
     */
340 70
    public function __construct($init = null, $options = [])
341
    {
342 70
        $this->init = $init;
343
344 70
        parent::__construct();
345 70
        $this->setUp($options);
346 70
        $this->curlInit();
347 70
        if (!empty($init)) {
348 22
            $this->processInit($init);
349 22
        }
350 70
    }
351
352
    /**
353
     * SetUp Object to be ready for connect
354
     *
355
     * @param array $options Object Options (company,url,user,password,evidence,
356
     *                                       prefix,defaultUrlParams,debug)
357
     */
358 71
    public function setUp($options = [])
359
    {
360 71
        $this->setupProperty($options, 'company', 'FLEXIBEE_COMPANY');
361 71
        $this->setupProperty($options, 'url', 'FLEXIBEE_URL');
362 71
        $this->setupProperty($options, 'user', 'FLEXIBEE_LOGIN');
363 71
        $this->setupProperty($options, 'password', 'FLEXIBEE_PASSWORD');
364 71
        if (isset($options['evidence'])) {
365 23
            $this->setEvidence($options['evidence']);
366 23
        }
367 71
        $this->setupProperty($options, 'defaultUrlParams');
368 71
        if (isset($options['prefix'])) {
369 23
            $this->setPrefix($options['prefix']);
370 23
        }
371 71
        if (array_key_exists('detail', $options)) {
372
            $this->defaultUrlParams['detail'] = $options['detail'];
373
        }
374 71
        $this->setupProperty($options, 'debug');
375 71
        $this->updateApiURL();
376 71
    }
377
378
    /**
379
     * Set up one of properties
380
     *
381
     * @param array  $options  array of given properties
382
     * @param string $name     name of property to process
383
     * @param string $constant load default property value from constant
384
     */
385 48
    public function setupProperty($options, $name, $constant = null)
386
    {
387 48
        if (isset($options[$name])) {
388
            $this->$name = $options[$name];
389
        } else {
390 48
            if (property_exists($this, $name) && !empty($constant) && defined($constant)) {
391 48
                $this->$name = constant($constant);
392 48
            }
393
        }
394 48
    }
395
396
    /**
397
     * Inicializace CURL
398
     */
399 94
    public function curlInit()
400
    {
401 94
        $this->curl = \curl_init(); // create curl resource
402 94
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); // return content as a string from curl_exec
403 94
        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); // follow redirects (compatibility for future changes in FlexiBee)
404 94
        curl_setopt($this->curl, CURLOPT_HTTPAUTH, true);       // HTTP authentication
405 94
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); // FlexiBee by default uses Self-Signed certificates
406 94
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
407 94
        curl_setopt($this->curl, CURLOPT_VERBOSE, ($this->debug === true)); // For debugging
408 94
        curl_setopt($this->curl, CURLOPT_USERPWD,
409 94
            $this->user.':'.$this->password); // set username and password
410 94
    }
411
412
    /**
413
     * Zinicializuje objekt dle daných dat. Možné hodnoty:
414
     *
415
     *  * 234                              - interní číslo záznamu k načtení
416
     *  * code:LOPATA                      - kód záznamu
417
     *  * BAGR                             - kód záznamu k načtení
418
     *  * ['id'=>24,'nazev'=>'hoblík']     - pole hodnot k předvyplnění
419
     *  * 743.json?relations=adresa,vazby  - část url s parametry k načtení
420
     *
421
     * @param mixed $init číslo/"(code:)kód"/(část)URI záznamu k načtení | pole hodnot k předvyplnění
422
     */
423 13
    public function processInit($init)
424
    {
425 13
        if (is_integer($init)) {
426 10
            $this->loadFromFlexiBee($init);
427 13
        } elseif (is_array($init)) {
428 13
            $this->takeData($init);
429 13
        } elseif (preg_match('/\.(json|xml|csv)/', $init)) {
430 10
            $this->takeData($this->getFlexiData((($init[0] != '/') ? $this->getEvidenceURL($init)
0 ignored issues
show
Unused Code introduced by
The call to FlexiBeeRO::getEvidenceURL() has too many arguments starting with $init.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
431 10
                            : $init)));
432 10
        } else {
433 8
            $this->loadFromFlexiBee($init);
434
        }
435 13
    }
436
437
    /**
438
     * Set URL prefix
439
     *
440
     * @param string $prefix
441
     */
442 23
    public function setPrefix($prefix)
443
    {
444
        switch ($prefix) {
445 23
            case 'a': //Access
446 23
            case 'c': //Company
447 23
            case 'u': //User
448 23
            case 'g': //License Groups
449 23
            case 'admin':
450 23
            case 'status':
451 23
            case 'login-logout':
452 23
                $this->prefix = '/'.$prefix.'/';
453 23
                break;
454 23
            case null:
455 23
            case '':
456 23
            case '/':
457 23
                $this->prefix = '';
458 23
                break;
459 23
            default:
460 23
                throw new \Exception(sprintf('Unknown prefix %s', $prefix));
461 23
        }
462 23
    }
463
464
    /**
465
     * Set communication format.
466
     * One of html|xml|json|csv|dbf|xls|isdoc|isdocx|edi|pdf|pdf|vcf|ical
467
     *
468
     * @param string $format
469
     * @return boolen format is availble
470
     */
471 23
    public function setFormat($format)
472
    {
473 23
        $result = true;
474 23
        if (($this->debug === true) && !empty($this->evidence) && isset(Formats::$$this->evidence)) {
475
            if (array_key_exists($format, array_flip(Formats::$$this->evidence))
476
                === false) {
477
                $result = false;
478
            }
479
        }
480 23
        if ($result === true) {
481 23
            $this->format = $format;
482 23
            $this->updateApiURL();
483 23
        }
484 23
        return $result;
485
    }
486
487
    /**
488
     * Nastaví Evidenci pro Komunikaci.
489
     * Set evidence for communication
490
     *
491
     * @param string $evidence evidence pathName to use
492
     * @return boolean evidence switching status
493
     */
494 23
    public function setEvidence($evidence)
495
    {
496 23
        switch ($this->prefix) {
497 23
            case '/c/':
498 23
                if ($this->debug === true) {
499 23
                    if (array_key_exists($evidence, EvidenceList::$name)) {
500
                        $this->evidence = $evidence;
501
                        $result         = true;
502
                    } else {
503 23
                        throw new \Exception(sprintf('Try to set unsupported evidence %s',
504 23
                                $evidence));
505
                    }
506
                } else {
507 20
                    $this->evidence = $evidence;
508 20
                    $result         = true;
509
                }
510 20
                break;
511 3
            default:
512 3
                $this->evidence = $evidence;
513 3
                $result         = true;
514 3
                break;
515 23
        }
516 23
        $this->updateApiURL();
517 23
        return $result;
518
    }
519
520
    /**
521
     * Vrací právě používanou evidenci pro komunikaci
522
     * Obtain current used evidence
523
     *
524
     * @return string
525
     */
526 69
    public function getEvidence()
527
    {
528 69
        return $this->evidence;
529
    }
530
531
    /**
532
     * Set used company.
533
     * Nastaví Firmu.
534
     *
535
     * @param string $company
536
     */
537 23
    public function setCompany($company)
538
    {
539 23
        $this->company = $company;
540 23
    }
541
542
    /**
543
     * Obtain company now used
544
     * Vrací právě používanou firmu
545
     *
546
     * @return string
547
     */
548 23
    public function getCompany()
549
    {
550 23
        return $this->company;
551
    }
552
553
    /**
554
     * Vrací název evidence použité v odpovědích z FlexiBee
555
     *
556
     * @return string
557
     */
558 25
    public function getResponseEvidence()
559
    {
560 25
        switch ($this->evidence) {
561 25
            case 'c':
562
                $evidence = 'company';
563
                break;
564 25
            case 'evidence-list':
565 1
                $evidence = 'evidence';
566 1
                break;
567 24
            default:
568 24
                $evidence = $this->getEvidence();
569 24
                break;
570 25
        }
571 25
        return $evidence;
572
    }
573
574
    /**
575
     * Převede rekurzivně Objekt na pole.
576
     *
577
     * @param object|array $object
578
     *
579
     * @return array
580
     */
581 23
    public static function object2array($object)
582
    {
583 23
        $result = null;
584 23
        if (is_object($object)) {
585 23
            $objectData = get_object_vars($object);
586 23
            if (is_array($objectData) && count($objectData)) {
587 23
                $result = array_map('self::object2array', $objectData);
588 23
            }
589 23
        } else {
590 23
            if (is_array($object)) {
591 23
                foreach ($object as $item => $value) {
592 23
                    $result[$item] = self::object2array($value);
593 23
                }
594 23
            } else {
595 23
                $result = $object;
596
            }
597
        }
598
599 23
        return $result;
600
    }
601
602
    /**
603
     * Převede rekurzivně v poli všechny objekty na jejich identifikátory.
604
     *
605
     * @param object|array $object
606
     *
607
     * @return array
608
     */
609 23
    public static function objectToID($object)
610
    {
611 23
        $resultID = null;
612 23
        if (is_object($object)) {
613 22
            $resultID = $object->__toString();
614 22
        } else {
615 23
            if (is_array($object)) {
616 17
                foreach ($object as $item => $value) {
617 17
                    $resultID[$item] = self::objectToID($value);
618 17
                }
619 17
            } else { //String
620 23
                $resultID = $object;
621
            }
622
        }
623
624 23
        return $resultID;
625
    }
626
627
    /**
628
     * Return basic URL for used Evidence
629
     *
630
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Sestavování URL
631
     *
632
     * @return string Evidence URL
633
     */
634 68
    public function getEvidenceURL()
635
    {
636 68
        $evidenceUrl = $this->url.$this->prefix.$this->company;
637 68
        $evidence    = $this->getEvidence();
638 68
        if (!empty($evidence)) {
639 62
            $evidenceUrl .= '/'.$evidence;
640 62
        }
641 68
        return $evidenceUrl;
642
    }
643
644
    /**
645
     * Add suffix to Evidence URL
646
     *
647
     * @param string $urlSuffix
648
     *
649
     * @return string
650
     */
651 23
    public function evidenceUrlWithSuffix($urlSuffix)
652
    {
653 23
        $evidenceUrl = $this->getEvidenceUrl();
654 23
        if (!empty($urlSuffix)) {
655 23
            if (($urlSuffix[0] != '/') && ($urlSuffix[0] != ';') && ($urlSuffix[0]
656 23
                != '?')) {
657 23
                $evidenceUrl .= '/';
658 23
            }
659 23
            $evidenceUrl .= $urlSuffix;
660 23
        }
661 23
        return $evidenceUrl;
662
    }
663
664
    /**
665
     * Update $this->apiURL
666
     */
667 48
    public function updateApiURL()
668
    {
669 48
        $this->apiURL = $this->getEvidenceURL();
670 48
        $id           = $this->__toString();
671 48
        if (!empty($id)) {
672
            $this->apiURL .= '/'.urlencode($id);
673
        }
674 48
        $this->apiURL .= '.'.$this->format;
675 48
    }
676
677
    /**
678
     * Add params to url
679
     *
680
     * @param string  $url      originall url
681
     * @param array   $params   value to add
682
     * @param boolean $override replace already existing values ?
683
     *
684
     * @return string url with parameters added
685
     */
686 23
    public function addUrlParams($url, $params, $override = false)
687
    {
688 23
        $urlParts = parse_url($url);
689 23
        $urlFinal = '';
690 23
        if (array_key_exists('scheme', $urlParts)) {
691 23
            $urlFinal .= $urlParts['scheme'].'://'.$urlParts['host'];
692 23
        }
693 23
        if (array_key_exists('port', $urlParts)) {
694 23
            $urlFinal .= ':'.$urlParts['port'];
695 23
        }
696 23
        if (array_key_exists('path', $urlParts)) {
697 23
            $urlFinal .= $urlParts['path'];
698 23
        }
699 23
        if (array_key_exists('query', $urlParts)) {
700 23
            parse_str($urlParts['query'], $queryUrlParams);
701
            $urlParams = $override ? array_merge($params, $queryUrlParams) : array_merge($queryUrlParams,
702
                    $params);
703 23
        } else {
704 23
            $urlParams = $params;
705 23
        }
706
707
        if (!empty($urlParams)) {
708 23
            $urlFinal .= '?';
709
            if (is_array($urlParams)) {
710
                $urlFinal .= http_build_query($urlParams);
711
            } else {
712
                $urlFinal .= $urlParams;
713
            }
714
        }
715
        return $urlFinal;
716
    }
717
718 23
    /**
719
     * Add Default Url params to given url if not overrided
720 23
     *
721
     * @param string $urlRaw
722
     *
723
     * @return string url with default params added
724
     */
725
    public function addDefaultUrlParams($urlRaw)
726
    {
727
        return $this->addUrlParams($urlRaw, $this->defaultUrlParams, false);
728
    }
729
730
    /**
731 25
     * Funkce, která provede I/O operaci a vyhodnotí výsledek.
732
     *
733
     * @param string $urlSuffix část URL za identifikátorem firmy.
734 25
     * @param string $method    HTTP/REST metoda
735
     * @param string $format    Requested format
736 25
     * @return array|boolean Výsledek operace
737
     */
738 25
    public function performRequest($urlSuffix = null, $method = 'GET',
739 4
                                   $format = null)
740 4
    {
741 22
        $this->rowCount = null;
742
743
        if (preg_match('/^http/', $urlSuffix)) {
744 25
            $url = $urlSuffix;
745
        } elseif (strlen($urlSuffix) && ($urlSuffix[0] == '/')) {
746 25
            $url = $this->url.$urlSuffix;
747 25
        } else {
748
            $url = $this->evidenceUrlWithSuffix($urlSuffix);
749
        }
750
751
        $responseCode = $this->doCurlRequest($url, $method, $format);
752
753
        return $this->parseResponse($this->rawResponseToArray($this->lastCurlResponse,
0 ignored issues
show
Bug introduced by
It seems like $this->rawResponseToArra... $this->responseFormat) targeting FlexiPeeHP\FlexiBeeRO::rawResponseToArray() can also be of type string; however, FlexiPeeHP\FlexiBeeRO::parseResponse() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
754
                    $this->responseFormat), $responseCode);
755
    }
756
757
    /**
758 3
     * Parse Raw FlexiBee response in several formats
759
     *
760 3
     * @param string $responseRaw raw response body
761
     * @param string $format      Raw Response format json|xml|etc
762 3
     *
763 3
     * @return array
764 3
     */
765
    public function rawResponseToArray($responseRaw, $format)
766
    {
767
        $responseDecoded = [];
768
        if (!empty(trim($responseRaw))) {
769
            switch ($format) {
770
                case 'json':
771
                    $responseDecoded = $this->rawJsonToArray($responseRaw);
772
                    break;
773 3
                case 'xml':
774
                    $responseDecoded = $this->rawXmlToArray($this->lastCurlResponse);
775 3
                    break;
776
                case 'txt':
777
                default:
778
                    $responseDecoded = $this->lastCurlResponse;
779
                    break;
780
            }
781
        }
782
        return $responseDecoded;
783
    }
784
785 3
    /**
786
     * Convert FlexiBee Response JSON to Array
787 3
     *
788 3
     * @param string $rawJson
789 3
     * 
790 3
     * @return array
791
     */
792
    public function rawJsonToArray($rawJson)
793 3
    {
794
        $responseDecoded = json_decode($rawJson, true, 10);
795
        $decodeError     = json_last_error_msg();
796
        if ($decodeError == 'No error') {
797 3
            if (array_key_exists($this->nameSpace, $responseDecoded)) {
798
                $responseDecoded = $responseDecoded[$this->nameSpace];
799
            }
800
        } else {
801
            $this->addStatusMessage('JSON Decoder: '.$decodeError, 'error');
802
            $this->addStatusMessage($rawJson, 'debug');
803
        }
804
        return $responseDecoded;
805
    }
806
807
    /**
808
     * Convert FlexiBee Response XML to Array
809
     *
810
     * @param string $rawXML
811
     *
812
     * @return array
813
     */
814
    public function rawXmlToArray($rawXML)
815
    {
816
        return self::xml2array($rawXML);
817
    }
818
819
    /**
820 3
     * Parse Response array
821
     *
822 3
     * @param array $responseDecoded
823
     * @param int $responseCode Request Response Code
824 3
     *
825
     * @return array main data part of response
826
     */
827
    public function parseResponse($responseDecoded, $responseCode)
828
    {
829
        $response = null;
830
        switch ($responseCode) {
831
            case 201: //Success Write
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
832 3
                if (isset($responseDecoded[$this->resultField][0]['id'])) {
833 3
                    $this->lastInsertedID = $responseDecoded[$this->resultField][0]['id'];
834 3
                    $this->setMyKey($this->lastInsertedID);
835
                    $this->apiURL         = $this->getEvidenceURL().'/'.$this->lastInsertedID;
836
                } else {
837 3
                    $this->lastInsertedID = null;
838
                }
839
            case 200: //Success Read
840 3
                $response         = $this->lastResult = $this->unifyResponseFormat($responseDecoded);
841
                if (isset($responseDecoded['@rowCount'])) {
842
                    $this->rowCount = (int) $responseDecoded['@rowCount'];
843
                }
844
                if (isset($responseDecoded['@globalVersion'])) {
845
                    $this->globalVersion = (int) $responseDecoded['@globalVersion'];
846
                }
847
                break;
848
849
            case 500: // Internal Server Error
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
850
                if ($this->debug === true) {
851
                    $this->error500Reporter($responseDecoded);
852
                }
853
            case 404: // Page not found
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
854
                if ($this->ignoreNotFound === true) {
855
                    break;
856
                }
857
            case 400: //Bad Request parameters
858
            default: //Something goes wrong
859
                $this->addStatusMessage($this->lastResponseCode.': '.$this->curlInfo['url'],
860 3
                    'warning');
861
                if (is_array($responseDecoded)) {
862
                    $this->parseError($responseDecoded);
863
                }
864
                $this->logResult($responseDecoded, $this->curlInfo['url']);
865
                break;
866
        }
867
        return $response;
868
    }
869
870
    /**
871
     * Parse error message response
872
     *
873
     * @param array $responseDecoded
874
     * @return int number of errors processed
875
     */
876
    public function parseError(array $responseDecoded)
877
    {
878
        if (array_key_exists('results', $responseDecoded)) {
879
            $this->errors = $responseDecoded['results'][0]['errors'];
880
        } else {
881
            if (array_key_exists('message', $responseDecoded)) {
882
                $this->errors = [['message' => $responseDecoded['message']]];
883
            }
884
        }
885
        return count($this->errors);
886
    }
887
888
    /**
889
     * Vykonej HTTP požadavek
890 3
     *
891
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Sestavování URL
892 3
     * @param string $url    URL požadavku
893 3
     * @param string $method HTTP Method GET|POST|PUT|OPTIONS|DELETE
894 3
     * @param string $format požadovaný formát komunikace
895 3
     * @return int HTTP Response CODE
896
     */
897 3
    public function doCurlRequest($url, $method, $format = null)
898
    {
899 3
        if (is_null($format)) {
900
            $format = $this->format;
901 3
        }
902
        curl_setopt($this->curl, CURLOPT_URL, $url);
903 3
// Nastavení samotné operace
904
        curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
905 3
//Vždy nastavíme byť i prázná postdata jako ochranu před chybou 411
906 3
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->postFields);
907 3
908 3
        $httpHeaders = $this->defaultHttpHeaders;
909 3
910 3
        $formats = Formats::bySuffix();
911 3
912 3
        if (!isset($httpHeaders['Accept'])) {
913 3
            $httpHeaders['Accept'] = $formats[$format]['content-type'];
914 3
        }
915 3
        if (!isset($httpHeaders['Content-Type'])) {
916 3
            $httpHeaders['Content-Type'] = $formats[$format]['content-type'];
917 3
        }
918
        $httpHeadersFinal = [];
919 3
        foreach ($httpHeaders as $key => $value) {
920
            if (($key == 'User-Agent') && ($value == 'FlexiPeeHP')) {
921
                $value .= ' v'.self::$libVersion;
922 3
            }
923 3
            $httpHeadersFinal[] = $key.': '.$value;
924 3
        }
925 3
926 3
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $httpHeadersFinal);
927 3
928 3
// Proveď samotnou operaci
929 3
        $this->lastCurlResponse            = curl_exec($this->curl);
930 3
        $this->curlInfo                    = curl_getinfo($this->curl);
931
        $this->curlInfo['when']            = microtime();
932
        $this->curlInfo['request_headers'] = $httpHeadersFinal;
933
        $this->responseFormat              = isset($this->curlInfo['content_type'])
934
                ? Formats::contentTypeToSuffix($this->curlInfo['content_type']) : 'txt';
935 3
        $this->lastResponseCode            = $this->curlInfo['http_code'];
936
        $this->lastCurlError               = curl_error($this->curl);
937
        if (strlen($this->lastCurlError)) {
938
            $this->addStatusMessage(sprintf('Curl Error (HTTP %d): %s',
939 3
                    $this->lastResponseCode, $this->lastCurlError), 'error');
940
        }
941
942
        if ($this->debug === true) {
943
            $this->saveDebugFiles();
944
        }
945
946
        return $this->lastResponseCode;
947
    }
948
949 23
    /**
950
     * Nastaví druh prováděné akce.
951 23
     *
952 23
     * @link https://demo.flexibee.eu/devdoc/actions Provádění akcí
953 23
     * @param string $action
954 23
     * @return boolean
955 15
     */
956 15
    public function setAction($action)
957 15
    {
958 23
        $result           = false;
959
        $actionsAvailable = $this->getActionsInfo();
960
        if (is_array($actionsAvailable) && array_key_exists($action,
961
                $actionsAvailable)) {
962
            $this->action = $action;
963
            $result       = true;
964
        }
965
        return $result;
966
    }
967
968 23
    /**
969
     * Convert XML to array.
970 23
     *
971 23
     * @param string $xml
972 23
     *
973 23
     * @return array
974 23
     */
975
    public static function xml2array($xml)
976 23
    {
977 23
        $arr = [];
978 23
        if (!empty($xml)) {
979 23
            if (is_string($xml)) {
980 23
                $xml = simplexml_load_string($xml);
981
            }
982 23
983 23
            foreach ($xml->children() as $r) {
984 23
                if (count($r->children()) == 0) {
985
                    $arr[$r->getName()] = strval($r);
986
                } else {
987
                    $arr[$r->getName()][] = self::xml2array($r);
988
                }
989
            }
990 1
        }
991
        return $arr;
992 1
    }
993 1
994 1
    /**
995 1
     * Odpojení od FlexiBee.
996 1
     */
997
    public function disconnect()
998
    {
999
        if (is_resource($this->curl)) {
1000
            curl_close($this->curl);
1001 1
        }
1002
        $this->curl = null;
1003 1
    }
1004 1
1005
    /**
1006
     * Disconnect CURL befere pass away
1007
     */
1008
    public function __destruct()
1009
    {
1010
        $this->disconnect();
1011
    }
1012
1013 23
    /**
1014
     * Načte řádek dat z FlexiBee.
1015 23
     *
1016 23
     * @param int $recordID id požadovaného záznamu
1017 22
     *
1018
     * @return array
1019
     */
1020
    public function getFlexiRow($recordID)
1021 22
    {
1022
        $record   = null;
1023
        $response = $this->performRequest($this->evidence.'/'.$recordID.'.json');
1024
        if (isset($response[$this->evidence])) {
1025
            $record = $response[$this->evidence][0];
1026
        }
1027
1028
        return $record;
1029
    }
1030
1031
    /**
1032
     * Oddělí z pole podmínek ty jenž patří za ? v URL požadavku
1033
     *
1034
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Sestavování URL
1035
     * @param array $conditions pole podmínek   - rendrují se do ()
1036
     * @param array $urlParams  pole parametrů  - rendrují za ?
1037
     */
1038
    public function extractUrlParams(&$conditions, &$urlParams)
1039
    {
1040
        foreach ($this->urlParams as $urlParam) {
1041
            if (isset($conditions[$urlParam])) {
1042
                \Ease\Sand::divDataArray($conditions, $urlParams, $urlParam);
1043
            }
1044
        }
1045
    }
1046
1047
    /**
1048
     * convert unicode to entities
1049
     *
1050
     * @param string $urlRaw
1051
     * @return string
1052
     */
1053
    public static function urlEncode($urlRaw)
1054
    {
1055
        return str_replace(['%27'], ["'"], rawurlencode($urlRaw));
1056
    }
1057
1058
    /**
1059 15
     * Načte data z FlexiBee.
1060
     *
1061 15
     * @param string $suffix     dotaz
1062 15
     * @param string|array $conditions Volitelný filtrovací výraz
1063
     *
1064 15
     * @return array Data obtained
1065 8
     */
1066 7
    public function getFlexiData($suffix = null, $conditions = null)
1067 7
    {
1068 7
        $finalUrl  = '';
1069
        $urlParams = $this->defaultUrlParams;
1070 8
1071 1
        if (!empty($conditions)) {
1072 1
            if (is_array($conditions)) {
1073 8
                $this->extractUrlParams($conditions, $urlParams);
1074
                $conditions = $this->flexiUrl($conditions);
1075 15
            }
1076 4
1077 4
            if (strlen($conditions) && ($conditions[0] != '/')) {
1078 4
                $conditions = '('.self::urlEncode($conditions).')';
1079
            }
1080
        }
1081
1082
        if (strlen($suffix)) {
1083 4
            if (preg_match('/^http/', $suffix) || ($suffix[0] == '/') || is_numeric($suffix)) {
1084
                $finalUrl = $suffix;
1085 15
            } else {
1086
                if (preg_match('/^(code|ext):(.*)/', $suffix, $matches)) {
1087 15
                    $finalUrl = $matches[1].':'.rawurlencode($matches[2]);
1088 15
                }
1089
            }
1090
        }
1091 15
1092
        $finalUrl .= $conditions;
1093 15
1094 15
        if (count($urlParams)) {
1095 15
            if (strstr($finalUrl, '?')) {
1096
                $finalUrl .= '&';
1097 15
            } else {
1098
                $finalUrl .= '?';
1099 15
            }
1100 15
            $finalUrl .= http_build_query($urlParams, null, '&',
1101 15
                PHP_QUERY_RFC3986);
1102 9
        }
1103 9
1104 6
        $transactions = $this->performRequest($finalUrl, 'GET');
1105 6
1106 9
        $responseEvidence = $this->getResponseEvidence();
1107 6
        if (is_array($transactions) && array_key_exists($responseEvidence,
1108
                $transactions)) {
1109
            $result = $transactions[$responseEvidence];
1110 15
            if ((count($result) == 1) && (count(current($result)) == 0 )) {
1111
                $result = null; // Response is empty Array
1112
            }
1113
        } else {
1114
            $result = $transactions;
1115
        }
1116
1117
        return $result;
1118
    }
1119
1120
    /**
1121 23
     * Načte záznam z FlexiBee a uloží v sobě jeho data
1122
     * Read FlexiBee record and store it inside od object
1123 23
     *
1124 23
     * @param int $id ID or conditions
1125 23
     *
1126 23
     * @return int počet načtených položek
1127 23
     */
1128
    public function loadFromFlexiBee($id = null)
1129
    {
1130
        $data = [];
1131 23
        if (is_null($id)) {
1132
            $id = $this->getMyKey();
1133
        }
1134
        if (is_array($id)) {
1135 23
            $id = rawurlencode('('.self::flexiUrl($id).')');
1136 22
        }
1137 22
1138 9
        if (preg_match('/^code/', $id)) {
1139 9
            $id = self::code(rawurlencode(self::uncode($id)));
1140 22
        }
1141
1142
        $flexidata    = $this->getFlexiData($this->getEvidenceUrl().'/'.$id);
1143
        $this->apiURL = $this->curlInfo['url'];
1144
        if (is_array($flexidata) && (count($flexidata) == 1)) {
1145
            $data = current($flexidata);
1146
        }
1147
        return $this->takeData($data);
1148
    }
1149
1150
    /**
1151 6
     * Převede data do Json formátu pro FlexiBee.
1152
     * Convert data to FlexiBee like Json format
1153
     * 
1154 6
     * @url https://www.flexibee.eu/api/dokumentace/ref/actions/
1155 6
     * @url https://www.flexibee.eu/api/dokumentace/ref/zamykani-odemykani/
1156 6
     *
1157 6
     * @param array $data
1158 6
     *
1159
     * @return string
1160 6
     */
1161
    public function jsonizeData($data)
1162
    {
1163
        $dataToJsonize = [
1164
            $this->nameSpace => [
1165 6
                '@version' => $this->protoVersion,
1166
                $this->evidence => $this->objectToID($data),
1167
            ],
1168
        ];
1169 6
1170 View Code Duplication
        if (!is_null($this->action)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1171
            $dataToJsonize[$this->nameSpace][$this->evidence.'@action'] = $this->action;
1172
            $this->action                                               = null;
1173
        }
1174
1175 View Code Duplication
        if (!is_null($this->filter)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1176
            $dataToJsonize[$this->nameSpace][$this->evidence.'@filter'] = $this->filter;
1177 16
        }
1178
1179 16
        return json_encode($dataToJsonize);
1180 9
    }
1181 9
1182 16
    /**
1183 16
     * Test if given record ID exists in FlexiBee.
1184 16
     *
1185
     * @param boolean $identifer presence state
1186 16
     */
1187 16
    public function idExists($identifer = null)
1188 16
    {
1189 15
        if (is_null($identifer)) {
1190 15
            $identifer = $this->getMyKey();
1191
        }
1192
        $ignorestate = $this->ignore404();
1193
        $this->ignore404(true);
1194
        $this->getFlexiData(null,
1195
            [
1196
                'detail' => 'custom:'.$this->getmyKeyColumn(),
1197
                $this->getmyKeyColumn() => $identifer
1198
        ]);
1199 15
        $this->ignore404($ignorestate);
1200
        return $this->lastResponseCode == 200;
1201
    }
1202 15
1203 10
    /**
1204 10
     * Test if given record exists in FlexiBee.
1205 15
     *
1206 15
     * @param array $data
1207 15
     * @return boolean Record presence status
1208 15
     */
1209
    public function recordExists($data = [])
1210 14
    {
1211 14
1212 14
        if (empty($data)) {
1213 14
            $data = $this->getData();
1214 10
        }
1215
        $ignorestate = $this->ignore404();
1216 14
        $this->ignore404(true);
1217 14
        $res         = $this->getColumnsFromFlexibee([$this->myKeyColumn],
1218
            [self::flexiUrl($data)]);
1219
1220
        if (!count($res) || (isset($res['success']) && ($res['success'] == 'false'))
1221
            || !count($res[0])) {
1222
            $found = false;
1223
        } else {
1224
            $found = true;
1225
        }
1226
        $this->ignore404($ignorestate);
1227
        return $found;
1228
    }
1229
1230
    /**
1231
     * Vrací z FlexiBee sloupečky podle podmínek.
1232
     *
1233
     * @param array|int|string $conditions pole podmínek nebo ID záznamu
1234
     * @param string           $indexBy    klice vysledku naplnit hodnotou ze
1235
     *                                     sloupečku
1236
     * @return array
1237
     */
1238
    public function getAllFromFlexibee($conditions = null, $indexBy = null)
1239
    {
1240
        if (is_int($conditions)) {
1241
            $conditions = [$this->getmyKeyColumn() => $conditions];
1242
        }
1243
1244
        $flexiData = $this->getFlexiData('', $conditions);
1245
1246
        if (!is_null($indexBy)) {
1247
            $flexiData = $this->reindexArrayBy($flexiData);
1248
        }
1249
1250
        return $flexiData;
1251
    }
1252 15
1253
    /**
1254
     * Vrací z FlexiBee sloupečky podle podmínek.
1255 15
     *
1256 15
     * @param string[] $columnsList seznam položek
1257 15
     * @param array    $conditions  pole podmínek nebo ID záznamu
1258
     * @param string   $indexBy     Sloupeček podle kterého indexovat záznamy
1259 15
     *
1260 15
     * @return array
1261 15
     */
1262 15
    public function getColumnsFromFlexibee($columnsList, $conditions = [],
1263 15
                                           $indexBy = null)
1264 15
    {
1265 15
        $detail = 'full';
1266 15
        switch (gettype($columnsList)) {
1267
            case 'integer': //Record ID
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
1268 15
                $conditions = [$this->getmyKeyColumn() => $conditions];
1269
            case 'array': //Few Conditions
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
1270
                if (!is_null($indexBy) && !array_key_exists($indexBy,
1271 15
                        $columnsList)) {
1272
                    $columnsList[] = $indexBy;
1273
                }
1274 15
                $columns = implode(',', array_unique($columnsList));
1275 15
                $detail  = 'custom:'.$columns;
1276 15
            default:
1277 15
                switch ($columnsList) {
1278 15
                    case 'id':
1279
                        $detail = 'id';
1280 15
                        break;
1281
                    case 'summary':
1282 15
                        $detail = 'summary';
1283
                        break;
1284 15
                    default:
1285 9
                        break;
1286 9
                }
1287
                break;
1288 15
        }
1289
1290
        $conditions['detail'] = $detail;
1291
1292
        $flexiData = $this->getFlexiData(null, $conditions);
1293
1294
        if (!is_null($indexBy) && count($flexiData) && count(current($flexiData))) {
1295
            $flexiData = $this->reindexArrayBy($flexiData, $indexBy);
1296
        }
1297
1298
        return $flexiData;
1299 23
    }
1300
1301 23
    /**
1302
     * Vrací kód záznamu.
1303 23
     * Obtain record CODE
1304 23
     *
1305 23
     * @param mixed $data
1306
     *
1307 23
     * @return string
1308 23
     */
1309 23
    public function getKod($data = null, $unique = true)
1310
    {
1311 23
        $kod = null;
1312 23
1313 23
        if (is_null($data)) {
1314 23
            $data = $this->getData();
1315 23
        }
1316 23
1317 23
        if (is_string($data)) {
1318 23
            $data = [$this->nameColumn => $data];
1319 23
        }
1320 23
1321
        if (isset($data['kod'])) {
1322
            $kod = $data['kod'];
1323
        } else {
1324 23
            if (isset($data[$this->nameColumn])) {
1325 23
                $kod = preg_replace('/[^a-zA-Z0-9]/', '',
1326 23
                    \Ease\Sand::rip($data[$this->nameColumn]));
1327
            } else {
1328 23
                if (isset($data[$this->myKeyColumn])) {
1329 23
                    $kod = \Ease\Sand::rip($data[$this->myKeyColumn]);
1330 23
                }
1331 23
            }
1332
        }
1333
1334 23
        if (!strlen($kod)) {
1335 23
            $kod = 'NOTSET';
1336 23
        }
1337 23
1338 23
        if (strlen($kod) > 18) {
1339 23
            $kodfinal = strtoupper(substr($kod, 0, 18));
1340 23
        } else {
1341 23
            $kodfinal = strtoupper($kod);
1342 23
        }
1343 23
1344 23
        if ($unique) {
1345 23
            $counter = 0;
1346
            if (count($this->codes)) {
1347 23
                foreach ($this->codes as $codesearch => $keystring) {
1348 23
                    if (strstr($codesearch, $kodfinal)) {
1349
                        ++$counter;
1350 23
                    }
1351
                }
1352
            }
1353
            if ($counter) {
1354
                $kodfinal = $kodfinal.$counter;
1355
            }
1356
1357
            $this->codes[$kodfinal] = $kod;
1358
        }
1359
1360 23
        return self::code($kodfinal);
1361
    }
1362 23
1363 23
    /**
1364 23
     * Write Operation Result.
1365
     *
1366
     * @param array  $resultData
1367 23
     * @param string $url        URL
1368 23
     * @return boolean Log save success
1369 23
     */
1370 23
    public function logResult($resultData = null, $url = null)
1371 23
    {
1372
        $logResult = false;
1373
        if (isset($resultData['success']) && ($resultData['success'] == 'false')) {
1374 23
            if (isset($resultData['message'])) {
1375 23
                $this->addStatusMessage($resultData['message'], 'warning');
1376 23
            }
1377
            $this->addStatusMessage('Error '.$this->lastResponseCode.': '.urldecode($url),
1378 23
                'warning');
1379 23
            unset($url);
1380 23
        }
1381 23
        if (is_null($resultData)) {
1382 23
            $resultData = $this->lastResult;
1383
        }
1384 23
        if (isset($url)) {
1385 23
            $this->logger->addStatusMessage($this->lastResponseCode.':'.urldecode($url));
1386 23
        }
1387 23
1388 23
        if (isset($resultData['results'])) {
1389
            if ($resultData['success'] == 'false') {
1390 23
                $status = 'error';
1391 23
            } else {
1392 23
                $status = 'success';
1393 23
            }
1394
            foreach ($resultData['results'] as $result) {
1395
                if (isset($result['request-id'])) {
1396 23
                    $rid = $result['request-id'];
1397
                } else {
1398
                    $rid = '';
1399 23
                }
1400
                if (isset($result['errors'])) {
1401
                    foreach ($result['errors'] as $error) {
1402 23
                        $message = $error['message'];
1403 23
                        if (isset($error['for'])) {
1404 23
                            $message .= ' for: '.$error['for'];
1405 23
                        }
1406 23
                        if (isset($error['value'])) {
1407 23
                            $message .= ' value:'.$error['value'];
1408
                        }
1409
                        if (isset($error['code'])) {
1410
                            $message .= ' code:'.$error['code'];
1411
                        }
1412
                        $this->addStatusMessage($rid.': '.$message, $status);
1413
                    }
1414
                }
1415
            }
1416
        }
1417
        return $logResult;
1418
    }
1419
1420
    /**
1421
     * Save RAW Curl Request & Response to files in Temp directory
1422
     */
1423
    public function saveDebugFiles()
1424
    {
1425
        $tmpdir   = sys_get_temp_dir();
1426
        $fname    = $this->evidence.'-'.$this->curlInfo['when'].'.'.$this->format;
1427
        $reqname  = $tmpdir.'/request-'.$fname;
1428
        $respname = $tmpdir.'/response-'.$fname;
1429
        file_put_contents($reqname, $this->postFields);
1430
        file_put_contents($respname, $this->lastCurlResponse);
1431
    }
1432
1433
    /**
1434
     * Připraví data pro odeslání do FlexiBee
1435
     *
1436
     * @param string $data
1437
     */
1438
    public function setPostFields($data)
1439
    {
1440
        $this->postFields = $data;
1441
    }
1442
1443
    /**
1444 23
     * Generuje fragment url pro filtrování.
1445
     *
1446 23
     * @see https://www.flexibee.eu/api/dokumentace/ref/filters
1447
     *
1448 23
     * @param array  $data
1449 23
     * @param string $joiner default and/or
1450 23
     * @param string $defop  default operator
1451 23
     *
1452 23
     * @return string
1453 23
     */
1454 23
    public static function flexiUrl(array $data, $joiner = 'and', $defop = 'eq')
1455 23
    {
1456 23
        $parts = [];
1457
1458 23
        foreach ($data as $column => $value) {
1459 23
            if (!is_numeric($column)) {
1460 23
                if (is_integer($data[$column]) || is_float($data[$column])) {
1461 23
                    $parts[$column] = $column.' eq \''.$data[$column].'\'';
1462 23
                } elseif (is_bool($data[$column])) {
1463
                    $parts[$column] = $data[$column] ? $column.' eq true' : $column.' eq false';
1464
                } elseif (is_null($data[$column])) {
1465 23
                    $parts[$column] = $column." is null";
1466 23
                } else {
1467
                    switch ($value) {
1468
                        case '!null':
1469 23
                            $parts[$column] = $column." is not null";
1470
                            break;
1471 23
                        case 'is empty':
1472 23
                        case 'is not empty':
1473
                            $parts[$column] = $column.' '.$value;
1474 23
                            break;
1475
                        default:
1476
                            if ($column == 'stitky') {
1477 23
                                $parts[$column] = $column."='".self::code($data[$column])."'";
1478 23
                            } else {
1479
                                $parts[$column] = $column." $defop '".$data[$column]."'";
1480
                            }
1481
                            break;
1482
                    }
1483
                }
1484
            } else {
1485
                $parts[] = $value;
1486
            }
1487
        }
1488
        return implode(' '.$joiner.' ', $parts);
1489 65
    }
1490
1491 65
    /**
1492 65
     * Obtain record/object numeric identificator id:
1493
     * Vrací číselný identifikátor objektu id:
1494
     *
1495 65
     * @link https://demo.flexibee.eu/devdoc/identifiers Identifikátory záznamů
1496 65
     *
1497
     * @return null|int indentifikátor záznamu reprezentovaného objektem
1498
     */
1499
    public function getRecordID()
1500
    {
1501 65
        $id = $this->getDataValue('id');
1502
        return is_null($id) ? null : intval($id);
1503
    }
1504
1505
    /**
1506
     * Obtain record/object identificator code:
1507
     * Vrací identifikátor objektu code:
1508
     *
1509
     * @link https://demo.flexibee.eu/devdoc/identifiers Identifikátory záznamů
1510
     *
1511 71
     * @return string record code identifier
1512
     */
1513 71
    public function getRecordCode()
1514
    {
1515
        return self::code($this->getDataValue('kod'));
1516
    }
1517
1518
    /**
1519
     * Obtain record/object identificator cdode: or id:
1520
     * Vrací identifikátor objektu code: nebo id:
1521
     *
1522 23
     * @link https://demo.flexibee.eu/devdoc/identifiers Identifikátory záznamů
1523
     *
1524 23
     * @return string|int|null record code identifier
1525
     */
1526
    public function getRecordIdent()
1527
    {
1528
        $ident = $this->getRecordCode();
1529
        if (empty($ident)) {
1530
            $ident = $this->getRecordID();
1531
        }
1532 15
        return $ident;
1533
    }
1534 15
1535 15
    /**
1536 15
     * Obtain record/object identificator code: or id:
1537 15
     * Vrací identifikátor objektu code: nebo id:
1538 15
     *
1539 9
     * @link https://demo.flexibee.eu/devdoc/identifiers Identifikátory záznamů
1540 9
     * @return string indentifikátor záznamu reprezentovaného objektem
1541 15
     */
1542
    public function __toString()
1543
    {
1544
        return strval($this->getRecordIdent());
1545
    }
1546
1547
    /**
1548
     * Gives you FlexiPeeHP class name for Given Evidence
1549
     *
1550 23
     * @param string $evidence
1551
     * @return string Class name
1552 23
     */
1553 23
    public static function evidenceToClassName($evidence)
1554 23
    {
1555 23
        return str_replace(' ', '', ucwords(str_replace('-', ' ', $evidence)));
1556 23
    }
1557 23
1558 23
    /**
1559 23
     * Obtain ID of first record in evidence
1560 23
     *
1561 23
     * @return string|null id or null if no records
1562 23
     */
1563 23
    public function getFirstRecordID()
1564 23
    {
1565 23
        $firstID    = null;
1566
        $keyColumn  = $this->getmyKeyColumn();
1567 23
        $firstIdRaw = $this->getColumnsFromFlexibee([$keyColumn],
1568
            ['limit' => 1, 'order' => $keyColumn], $keyColumn);
1569
        if (count($firstIdRaw)) {
1570
            $firstID = current($firstIdRaw)[$keyColumn];
1571
        }
1572
        return is_numeric($firstID) ? intval($firstID) : $firstID;
1573
    }
1574
1575
    /**
1576
     * Vrací hodnotu daného externího ID
1577 22
     *
1578
     * @param string $want Which ? If empty,you obtain the first one.
1579 22
     * @return string
1580
     */
1581 21
    public function getExternalID($want = null)
1582
    {
1583
        $extid = null;
1584
        $ids   = $this->getDataValue('external-ids');
1585
        if (is_null($want)) {
1586
            if (count($ids)) {
1587
                $extid = current($ids);
1588
            }
1589 22
        } else {
1590
            if (!is_null($ids) && is_array($ids)) {
1591 22
                foreach ($ids as $id) {
1592 22
                    if (strstr($id, 'ext:'.$want)) {
1593 22
                        $extid = str_replace('ext:'.$want.':', '', $id);
1594
                    }
1595
                }
1596 22
            }
1597
        }
1598
        return $extid;
1599
    }
1600
1601
    /**
1602
     * Obtain actual GlobalVersion
1603
     * Vrací aktuální globální verzi změn
1604
     *
1605 22
     * @link https://www.flexibee.eu/api/dokumentace/ref/changes-api#globalVersion Globální Verze
1606
     * @return type
1607 22
     */
1608 22
    public function getGlobalVersion()
1609 22
    {
1610 22
        $this->getFlexiData(null, ['add-global-version' => 'true', 'limit' => 1]);
1611 22
1612 22
        return $this->globalVersion;
1613 22
    }
1614 22
1615 22
    /**
1616 22
     * Obtain content type of last response
1617 22
     *
1618 22
     * @return string
1619
     */
1620 22
    public function getResponseFormat()
1621
    {
1622
        if (isset($this->curlInfo['content_type'])) {
1623
            $responseFormat = $this->curlInfo['content_type'];
1624
        } else {
1625
            $responseFormat = null;
1626
        }
1627
        return $responseFormat;
1628
    }
1629
1630
    /**
1631
     * Return the same response format for one and multiplete results
1632 22
     *
1633
     * @param array $responseBody
1634
     * @return array
1635
     */
1636
    public function unifyResponseFormat($responseBody)
1637
    {
1638
        if (!is_array($responseBody) || array_key_exists('message',
1639
                $responseBody)) { //Unifi response format
1640
            $response = $responseBody;
1641 23
        } else {
1642
            $evidence = $this->getResponseEvidence();
1643 23
            if (array_key_exists($evidence, $responseBody)) {
1644 23
                $response        = [];
1645 23
                $evidenceContent = $responseBody[$evidence];
1646 23
                if (array_key_exists(0, $evidenceContent)) {
1647 16
                    $response[$evidence] = $evidenceContent; //Multiplete Results
1648 16
                } else {
1649 23
                    $response[$evidence][0] = $evidenceContent; //One result
1650
                }
1651
            } else {
1652
                if (isset($responseBody['priloha'])) {
1653
                    $response = $responseBody['priloha'];
1654
                } else {
1655
                    if (array_key_exists('results', $responseBody)) {
1656
                        $response = $responseBody['results'];
1657
                    } else {
1658 23
                        $response = $responseBody;
1659
                    }
1660 23
                }
1661 23
            }
1662 23
        }
1663 23
        return $response;
1664 23
    }
1665 23
1666 23
    /**
1667 23
     * Obtain structure for current (or given) evidence
1668 23
     *
1669
     * @param string $evidence
1670
     * @return array Evidence structure
1671
     */
1672
    public function getColumnsInfo($evidence = null)
1673
    {
1674
        $columnsInfo = null;
1675
        $infoSource  = self::$infoDir.'/Properties.'.(empty($evidence) ? $this->getEvidence()
1676
                : $evidence).'.json';
1677 23
        if (file_exists($infoSource)) {
1678
            $columnsInfo = json_decode(file_get_contents($infoSource), true);
1679 23
        }
1680 23
        return $columnsInfo;
1681 23
    }
1682 23
1683 23
    /**
1684 23
     * Obtain actions for current (or given) evidence
1685 13
     *
1686 13
     * @param string $evidence
1687 23
     * @return array Evidence structure
1688
     */
1689
    public function getActionsInfo($evidence = null)
1690
    {
1691
        $actionsInfo = null;
1692
        if (is_null($evidence)) {
1693
            $evidence = $this->getEvidence();
1694
        }
1695
        $propsName = lcfirst(FlexiBeeRO::evidenceToClassName($evidence));
1696 23
        if (isset(\FlexiPeeHP\Actions::$$propsName)) {
1697
            $actionsInfo = Actions::$$propsName;
1698 23
        }
1699 23
        return $actionsInfo;
1700 23
    }
1701 23
1702 23
    /**
1703 16
     * Obtain relations for current (or given) evidence
1704 16
     *
1705 23
     * @param string $evidence
1706
     * @return array Evidence structure
1707
     */
1708
    public function getRelationsInfo($evidence = null)
1709
    {
1710
        $relationsInfo = null;
1711
        if (is_null($evidence)) {
1712
            $evidence = $this->getEvidence();
1713
        }
1714 23
        $propsName = lcfirst(FlexiBeeRO::evidenceToClassName($evidence));
1715
        if (isset(\FlexiPeeHP\Relations::$$propsName)) {
1716 23
            $relationsInfo = Relations::$$propsName;
1717 23
        }
1718 23
        return $relationsInfo;
1719 23
    }
1720 23
1721 16
    /**
1722 16
     * Obtain info for current (or given) evidence
1723 23
     *
1724
     * @param string $evidence
1725
     * @return array Evidence info
1726
     */
1727 View Code Duplication
    public function getEvidenceInfo($evidence = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1728
    {
1729
        $evidencesInfo = null;
1730
        if (is_null($evidence)) {
1731 23
            $evidence = $this->getEvidence();
1732
        }
1733 23
        if (isset(EvidenceList::$evidences[$evidence])) {
1734 1
            $evidencesInfo = EvidenceList::$evidences[$evidence];
1735 1
        }
1736 23
        return $evidencesInfo;
1737 23
    }
1738
1739
    /**
1740
     * Obtain name for current (or given) evidence path
1741
     *
1742
     * @param string $evidence Evidence Path
1743
     * @return array Evidence info
1744 20
     */
1745 View Code Duplication
    public function getEvidenceName($evidence = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1746 20
    {
1747 20
        $evidenceName = null;
1748 20
        if (is_null($evidence)) {
1749 20
            $evidence = $this->getEvidence();
1750
        }
1751
        if (isset(EvidenceList::$name[$evidence])) {
1752
            $evidenceName = EvidenceList::$name[$evidence];
1753
        }
1754
        return $evidenceName;
1755 20
    }
1756
1757
    /**
1758
     * Save current object to file
1759
     *
1760
     * @param string $destfile path to file
1761
     */
1762
    public function saveResponseToFile($destfile)
1763
    {
1764
        if (strlen($this->lastCurlResponse)) {
1765
            $this->doCurlRequest($this->apiURL, 'GET', $this->format);
1766
        }
1767
        file_put_contents($destfile, $this->lastCurlResponse);
1768
    }
1769
1770
    /**
1771
     * Obtain established relations listing
1772
     *
1773
     * @return array Null or Relations
1774
     */
1775
    public function getVazby($id = null)
1776
    {
1777
        if (is_null($id)) {
1778
            $id = $this->getRecordID();
1779
        }
1780
        if (!empty($id)) {
1781
            $vazbyRaw = $this->getColumnsFromFlexibee(['vazby'],
1782
                ['relations' => 'vazby', 'id' => $id]);
1783
            $vazby    = array_key_exists('vazby', $vazbyRaw[0]) ? $vazbyRaw[0]['vazby']
1784
                    : null;
1785
        } else {
1786
            throw new \Exception(_('ID requied to get record relations '));
1787
        }
1788
        return $vazby;
1789
    }
1790
1791
    /**
1792
     * Gives You URL for Current Record in FlexiBee web interface
1793
     *
1794
     * @return string url
1795
     */
1796
    public function getFlexiBeeURL()
1797
    {
1798
        $parsed_url = parse_url(str_replace('.'.$this->format, '', $this->apiURL));
1799
        $scheme     = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://'
1800
                : '';
1801
        $host       = isset($parsed_url['host']) ? $parsed_url['host'] : '';
1802
        $port       = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
1803
        $user       = isset($parsed_url['user']) ? $parsed_url['user'] : '';
1804
        $pass       = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
1805
        $pass       = ($user || $pass) ? "$pass@" : '';
1806
        $path       = isset($parsed_url['path']) ? $parsed_url['path'] : '';
1807
        return $scheme.$user.$pass.$host.$port.$path;
1808
    }
1809
1810
    /**
1811
     * Set Record Key
1812
     *
1813
     * @param int|string $myKeyValue
1814
     * @return boolean
1815
     */
1816
    public function setMyKey($myKeyValue)
1817
    {
1818
        $res = parent::setMyKey($myKeyValue);
1819
        $this->updateApiURL();
1820
        return $res;
1821
    }
1822
1823
    /**
1824
     * Set or get ignore not found pages flag
1825
     *
1826
     * @param boolean $ignore set flag to
1827
     *
1828
     * @return boolean get flag state
1829
     */
1830
    public function ignore404($ignore = null)
1831
    {
1832
        if (!is_null($ignore)) {
1833
            $this->ignoreNotFound = $ignore;
1834
        }
1835
        return $this->ignoreNotFound;
1836
    }
1837
1838
    /**
1839
     * Send Document by mail
1840
     *
1841
     * @url https://www.flexibee.eu/api/dokumentace/ref/odesilani-mailem/
1842
     *
1843
     * @param string $to         Email ecipient
1844
     * @param string $subject    Email Subject
1845 23
     * @param string $body       Email Text
1846
     *
1847 23
     * @return int http response code
1848
     */
1849
    public function sendByMail($to, $subject, $body, $cc = null)
1850
    {
1851
        $this->setPostFields($body);
1852
1853
        $this->performRequest(rawurlencode($this->getRecordID()).'/odeslani-dokladu?to='.$to.'&subject='.urlencode($subject).'&cc='.$cc
1854
            , 'PUT', 'xml');
1855
1856
        return $this->lastResponseCode == 200;
1857 23
    }
1858
1859 23
    /**
1860
     * Send all unsent Invoices by mail
1861
     *
1862
     * @url https://www.flexibee.eu/api/dokumentace/ref/odesilani-mailem/
1863
     * @return int http response code
1864
     */
1865
    public function sendUnsent()
1866
    {
1867
        return $this->doCurlRequest('automaticky-odeslat-neodeslane', 'PUT',
1868
                'xml');
1869
    }
1870
1871
    /**
1872
     * FlexiBee date to PHP DateTime conversion
1873
     *
1874
     * @param string $flexidate 2017-05-26+02:00
1875
     *
1876
     * @return \DateTime | false
1877
     */
1878
    public static function flexiDateToDateTime($flexidate)
1879
    {
1880
        return \DateTime::createFromFormat('Y-m-dO', $flexidate)->setTime(0, 0);
1881
    }
1882
1883
    /**
1884
     * FlexiBee dateTime to PHP DateTime conversion
1885
     *
1886
     * @param string $flexidatetime 2017-09-26T10:00:53.755+02:00 or older 2017-05-19T00:00:00+02:00
1887
     *
1888
     * @return \DateTime | false
1889
     */
1890
    public static function flexiDateTimeToDateTime($flexidatetime)
1891
    {
1892
        if(strchr($flexidatetime, '.')){ //NewFormat
1893
            $format = 'Y-m-d\TH:i:s.u+P';
1894
        } else { // Old format
1895
            $format = 'Y-m-d\TH:i:s+P';
1896
    }
1897
        return \DateTime::createFromFormat($format, $flexidatetime);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor...ormat, $flexidatetime); of type DateTime|false adds false to the return on line 1897 which is incompatible with the return type documented by FlexiPeeHP\FlexiBeeRO::flexiDateTimeToDateTime of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
1898
    }
1899
1900
    /**
1901
     * Získá dokument v daném formátu
1902
     * Obtain document in given format
1903
     *
1904
     * @param string $format  pdf/csv/xml/json/ ...
1905
     * @param string $reportName Template used to generate PDF
0 ignored issues
show
Bug introduced by
There is no parameter named $reportName. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1906
     *
1907
     * @return string|null filename downloaded or none
1908
     */
1909
    public function getInFormat($format)
1910
    {
1911
        $response = null;
1912
        if ($this->setFormat($format)) {
1913
            $urlParams = [];
1914
            if (!empty($reportName)) {
0 ignored issues
show
Bug introduced by
The variable $reportName seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
1915
                $urlParams['report-name'] = $reportName;
1916
            }
1917
            if ($format == 'html') {
1918
                $urlParams['inDesktopApp'] = 'true';
1919
            }
1920
            if (($this->doCurlRequest($this->addUrlParams($this->apiURL,
1921
                        $urlParams), 'GET') == 200)) {
1922
                $response = $this->lastCurlResponse;
1923
            }
1924
        }
1925
        return $response;
1926
    }
1927
1928
    /**
1929
     * Uloží dokument v daném formátu do složky v systému souborů
1930
     * Save document in given format to directory in filesystem
1931
     *
1932
     * @param string $format  pdf/csv/xml/json/ ...
1933
     * @param string $destDir where to put file (prefix)
1934
     * @param string $reportName Template used to generate PDF
1935
     *
1936
     * @return string|null filename downloaded or none
1937
     */
1938
    public function downloadInFormat($format, $destDir = './',
1939
                                     $reportName = null)
1940
    {
1941
        $fileOnDisk   = null;
1942
        $formatBackup = $this->format;
1943
        if ($this->setFormat($format)) {
1944
            $downloadTo = $destDir.$this->getEvidence().'_'.$this->getMyKey().'.'.$format;
1945
            if (($this->doCurlRequest(empty($reportName) ? $this->apiURL : $this->addUrlParams($this->apiURL,
1946
                            ['report-name' => $reportName]), 'GET') == 200) && (file_put_contents($downloadTo,
1947
                    $this->lastCurlResponse) !== false)) {
1948
                $fileOnDisk = $downloadTo;
1949
            }
1950
            $this->setFormat($formatBackup);
1951
        }
1952
        return $fileOnDisk;
1953
    }
1954
1955
    /**
1956
     * Compile and send Report about Error500 to FlexiBee developers
1957
     * If FlexiBee is running on localost try also include java backtrace
1958
     *
1959
     * @param array $errorResponse result of parseError();
1960
     */
1961
    public function error500Reporter($errorResponse)
1962
    {
1963
        $ur = str_replace('/c/'.$this->company, '',
1964
            str_replace($this->url, '', $this->curlInfo['url']));
1965
        if (!array_key_exists($ur, $this->reports)) {
1966
            $tmpdir   = sys_get_temp_dir();
1967
            $myTime   = $this->curlInfo['when'];
1968
            $curlname = $tmpdir.'/curl-'.$this->evidence.'-'.$myTime.'.json';
1969
            file_put_contents($curlname,
1970
                json_encode($this->curlInfo, JSON_PRETTY_PRINT));
1971
1972
            $report = new \Ease\Mailer($this->reportRecipient,
1973
                'Error report 500 - '.$ur);
1974
1975
            $d     = dir($tmpdir);
1976
            while (false !== ($entry = $d->read())) {
1977
                if (strstr($entry, $myTime)) {
1978
                    $ext  = pathinfo($tmpdir.'/'.$entry, PATHINFO_EXTENSION);
1979
                    $mime = Formats::suffixToContentType($ext);
1980
                    $report->addFile($tmpdir.'/'.$entry,
1981
                        empty($mime) ? 'text/plain' : $mime);
1982
                }
1983
            }
1984
            $d->close();
1985
1986
            if ((strstr($this->url, '://localhost') || strstr($this->url,
1987
                    '://127.')) && file_exists('/var/log/flexibee.log')) {
1988
1989
                $fl = fopen("/var/log/flexibee.log", "r");
1990
                if ($fl) {
1991
                    $tracelog = [];
1992
                    for ($x_pos = 0, $ln = 0, $output = array(); fseek($fl,
1993
                            $x_pos, SEEK_END) !== -1; $x_pos--) {
1994
                        $char = fgetc($fl);
1995
                        if ($char === "\n") {
1996
                            $tracelog[] = $output[$ln];
1997
                            if (strstr($output[$ln], $errorResponse['message'])) {
1998
                                break;
1999
                            }
2000
                            $ln++;
2001
                            continue;
2002
                        }
2003
                        $output[$ln] = $char.((array_key_exists($ln, $output)) ? $output[$ln]
2004
                                : '');
2005
                    }
2006
2007
                    $trace     = implode("\n", array_reverse($tracelog));
2008
                    $tracefile = $tmpdir.'/trace-'.$this->evidence.'-'.$myTime.'.log';
2009
                    file_put_contents($tracefile, $trace);
2010
                    $report->addItem("\n\n".$trace);
2011
                    fclose($fl);
2012
                }
2013
            } else {
2014
                $report->addItem($errorResponse['message']);
2015
            }
2016
2017
            $licenseInfo = $this->performRequest($this->url.'/default-license.json');
2018
2019
            $report->addItem("\n\n".json_encode($licenseInfo['license'],
2020
                    JSON_PRETTY_PRINT));
2021
2022
            if ($report->send()) {
2023
                $this->reports[$ur] = $myTime;
2024
            }
2025
        }
2026
    }
2027
2028
    /**
2029
     * Returns code:CODE
2030
     *
2031
     * @param string $code
2032
     *
2033
     * @return string
2034
     */
2035 23
    public static function code($code)
2036
    {
2037 23
        return 'code:'.self::uncode($code);
2038 23
    }
2039 23
2040 23
    /**
2041
     * Returns CODE without code: prefix
2042
     *
2043
     * @param string $code
2044
     *
2045
     * @return string
2046
     */
2047
    public static function uncode($code)
2048
    {
2049
        return str_replace(['code:', 'code%3A'], '', $code);
2050
    }
2051
2052
    /**
2053
     * Remove all @ items from array
2054
     *
2055
     * @param array $data original data
2056
     *
2057
     * @return array data without @ columns
2058
     */
2059
    public static function arrayCleanUP($data)
2060
    {
2061
        return array_filter(
2062
            $data,
2063
            function ($key) {
2064
            return !strchr($key, '@');
2065
        }, ARRAY_FILTER_USE_KEY);
2066
    }
2067
2068
    /**
2069
     * Add Info about used user, server and libraries
2070
     *
2071
     * @param string $additions Additional note text
2072
     */
2073
    function logBanner($additions = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2074
    {
2075
        $this->addStatusMessage('FlexiBee '.str_replace('://',
2076
                '://'.$this->user.'@', str_replace('.json', '', $this->apiURL)).' FlexiPeeHP v'.self::$libVersion.' (FlexiBee '.EvidenceList::$version.') EasePHP Framework v'.\Ease\Atom::$frameworkVersion.' '.$additions,
2077
            'debug');
2078
    }
2079
2080
    /**
2081
     * Reconnect After unserialization
2082
     */
2083
    public function __wakeup()
2084
    {
2085
        parent::__wakeup();
2086
        $this->curlInit();
2087
    }
2088
}
2089