1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheAentMachine\Aenthill; |
5
|
|
|
|
6
|
|
|
use TheAentMachine\Exception\ManifestException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Utility class to access the manifest data. |
10
|
|
|
*/ |
11
|
|
|
class Manifest |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param string[] $events |
16
|
|
|
*/ |
17
|
|
|
public static function setEvents(array $events): void |
18
|
|
|
{ |
19
|
|
|
Aenthill::update(null, $events); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public static function addMetadata(string $key, string $value): void |
23
|
|
|
{ |
24
|
|
|
Aenthill::update([$key => $value]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $key |
29
|
|
|
* @return string |
30
|
|
|
* @throws ManifestException |
31
|
|
|
*/ |
32
|
|
|
public static function getMetadata(string $key): string |
33
|
|
|
{ |
34
|
|
|
try { |
35
|
|
|
return Aenthill::metadata($key); |
36
|
|
|
} catch (\Exception $e) { |
37
|
|
|
throw ManifestException::missingMetadata($key); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $key |
43
|
|
|
* @return null|string |
44
|
|
|
*/ |
45
|
|
|
public static function getMetadataOrNull(string $key): ?string |
46
|
|
|
{ |
47
|
|
|
try { |
48
|
|
|
return self::getMetadata($key); |
49
|
|
|
} catch (ManifestException $e) { |
50
|
|
|
return null; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $image |
56
|
|
|
* @param string $key |
57
|
|
|
* @param array<string,string>|null $metadata |
58
|
|
|
*/ |
59
|
|
|
public static function addDependency(string $image, string $key, ?array $metadata): void |
60
|
|
|
{ |
61
|
|
|
Aenthill::register($image, $key, $metadata); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $key |
66
|
|
|
* @return string |
67
|
|
|
* @throws ManifestException |
68
|
|
|
*/ |
69
|
|
|
public static function getDependency(string $key): string |
70
|
|
|
{ |
71
|
|
|
try { |
72
|
|
|
return Aenthill::dependency($key); |
73
|
|
|
} catch (\Exception $e) { |
74
|
|
|
throw ManifestException::missingDependency($key); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $key |
81
|
|
|
* @return null|string |
82
|
|
|
*/ |
83
|
|
|
public static function getDependencyOrNull(string $key): ?string |
84
|
|
|
{ |
85
|
|
|
try { |
86
|
|
|
return self::getDependency($key); |
87
|
|
|
} catch (ManifestException $e) { |
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|