|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* The Imaging Source Download System PHP Wrapper |
|
6
|
|
|
* |
|
7
|
|
|
* PHP wrapper for The Imaging Source Download System Web API. Authored and supported by The Imaging Source Europe GmbH. |
|
8
|
|
|
* |
|
9
|
|
|
* @link http://dl-gui.theimagingsource.com to learn more about The Imaging Source Download System |
|
10
|
|
|
* @link https://github.com/jonathanmaron/theimagingsource-tisd-sdk for the canonical source repository |
|
11
|
|
|
* @license https://github.com/jonathanmaron/theimagingsource-tisd-sdk/blob/master/LICENSE.md |
|
12
|
|
|
* @copyright © 2022 The Imaging Source Europe GmbH |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Tisd\Sdk; |
|
16
|
|
|
|
|
17
|
|
|
use RecursiveArrayIterator; |
|
18
|
|
|
use RecursiveIteratorIterator; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Trait PackageTrait |
|
22
|
|
|
* |
|
23
|
|
|
* @package Tisd\Sdk |
|
24
|
|
|
*/ |
|
25
|
|
|
trait PackageTrait |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Get the array of consolidated data |
|
29
|
|
|
* |
|
30
|
|
|
* @return array |
|
31
|
|
|
*/ |
|
32
|
|
|
abstract protected function getConsolidated(): array; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get array of package data matching uuid |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $uuid |
|
38
|
|
|
* |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function getPackageByUuid(string $uuid): array |
|
42
|
|
|
{ |
|
43
|
1 |
|
return $this->getPackageByKeyValue('uuid', $uuid); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get array of package data matching product code ID |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $productCodeId |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function getPackageByProductCodeId(string $productCodeId): array |
|
54
|
|
|
{ |
|
55
|
1 |
|
return $this->getPackageByKeyValue('product_code_id', $productCodeId); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get array of package data matching package ID |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $packageId |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function getPackageByPackageId(string $packageId): array |
|
66
|
|
|
{ |
|
67
|
1 |
|
return $this->getPackageByKeyValue('package_id', $packageId); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get array of package data matching product code |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $productCode |
|
74
|
|
|
* |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
2 |
|
public function getPackageByProductCode(string $productCode): array |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->getPackageByKeyValue('product_code', $productCode); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get array of package data where specified $key equals specified $value |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $key |
|
86
|
|
|
* @param string $value |
|
87
|
|
|
* |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
5 |
|
private function getPackageByKeyValue(string $key, string $value): array |
|
91
|
|
|
{ |
|
92
|
5 |
|
$consolidated = $this->getConsolidated(); |
|
93
|
|
|
|
|
94
|
5 |
|
$rai = new RecursiveArrayIterator($consolidated['packages']); |
|
95
|
5 |
|
$rii = new RecursiveIteratorIterator($rai, RecursiveIteratorIterator::SELF_FIRST); |
|
96
|
|
|
|
|
97
|
5 |
|
foreach ($rii as $package) { |
|
98
|
|
|
|
|
99
|
5 |
|
if (!is_array($package)) { |
|
100
|
5 |
|
continue; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
5 |
|
if (!array_key_exists('package_id', $package)) { |
|
104
|
5 |
|
continue; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
5 |
|
if ($package[$key] === $value) { |
|
108
|
4 |
|
return $package; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
1 |
|
return []; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|