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 Tisd\Sdk\Exception\InvalidArgumentException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Trait MetaTrait |
21
|
|
|
* |
22
|
|
|
* @package Tisd\Sdk |
23
|
|
|
*/ |
24
|
|
|
trait MetaTrait |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Get the array of consolidated data |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
abstract protected function getConsolidated(): array; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the array of meta-data |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
5 |
|
public function getMeta(): array |
39
|
|
|
{ |
40
|
5 |
|
$ret = []; |
41
|
|
|
|
42
|
5 |
|
$consolidated = $this->getConsolidated(); |
43
|
|
|
|
44
|
5 |
|
if (isset($consolidated['meta'])) { |
45
|
5 |
|
$ret = $consolidated['meta']; |
46
|
|
|
} |
47
|
|
|
|
48
|
5 |
|
return $ret; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get the category count |
53
|
|
|
* |
54
|
|
|
* @return int |
55
|
|
|
*/ |
56
|
1 |
|
public function getCategoryCount(): int |
57
|
|
|
{ |
58
|
1 |
|
$ret = 0; |
59
|
|
|
|
60
|
1 |
|
$meta = $this->getMeta(); |
61
|
1 |
|
if (isset($meta['category']['count'])) { |
62
|
1 |
|
$ret = (int) $meta['category']['count']; |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
return $ret; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the section count |
70
|
|
|
* |
71
|
|
|
* @return int |
72
|
|
|
*/ |
73
|
1 |
|
public function getSectionCount(): int |
74
|
|
|
{ |
75
|
1 |
|
$ret = 0; |
76
|
|
|
|
77
|
1 |
|
$meta = $this->getMeta(); |
78
|
1 |
|
if (isset($meta['section']['count'])) { |
79
|
1 |
|
$ret = $meta['section']['count']; |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
return $ret; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the package count |
87
|
|
|
* |
88
|
|
|
* @return int |
89
|
|
|
*/ |
90
|
1 |
|
public function getPackageCount(): int |
91
|
|
|
{ |
92
|
1 |
|
$ret = 0; |
93
|
|
|
|
94
|
1 |
|
$meta = $this->getMeta(); |
95
|
1 |
|
if (isset($meta['package']['count'])) { |
96
|
1 |
|
$ret = (int) $meta['package']['count']; |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
return $ret; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the build time |
104
|
|
|
* |
105
|
|
|
* @param string $type |
106
|
|
|
* |
107
|
|
|
* @return mixed |
108
|
|
|
*/ |
109
|
2 |
|
public function getBuildTime(string $type = 'timestamp') |
110
|
|
|
{ |
111
|
2 |
|
$ret = null; |
112
|
|
|
|
113
|
2 |
|
$types = [ |
114
|
2 |
|
'timestamp', |
115
|
2 |
|
'rtf_2822', |
116
|
2 |
|
'iso_8601', |
117
|
2 |
|
]; |
118
|
|
|
|
119
|
2 |
|
if (!in_array($type, $types, true)) { |
120
|
1 |
|
$format = '"type" must be one of %s'; |
121
|
1 |
|
$message = sprintf($format, implode(', ', $types)); |
122
|
1 |
|
throw new InvalidArgumentException($message); |
123
|
|
|
} |
124
|
|
|
|
125
|
1 |
|
$meta = $this->getMeta(); |
126
|
|
|
|
127
|
1 |
|
if (isset($meta['build']['time'][$type])) { |
128
|
1 |
|
$ret = $meta['build']['time'][$type]; |
129
|
|
|
} |
130
|
|
|
|
131
|
1 |
|
return $ret; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|