1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the KongAdminApi package. |
5
|
|
|
* |
6
|
|
|
* (c) Unikorp <https://github.com/unikorp> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Unikorp\KongAdminApi; |
13
|
|
|
|
14
|
|
|
use Unikorp\KongAdminApi\Node; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* configurator |
18
|
|
|
* |
19
|
|
|
* @author VEBER Arnaud <https://github.com/VEBERArnaud> |
20
|
|
|
*/ |
21
|
|
|
class Configurator implements ConfiguratorInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* base uri |
25
|
|
|
* @var string $baseUri |
26
|
|
|
*/ |
27
|
|
|
private $baseUri = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* nodes |
31
|
|
|
* @var array $nodes |
32
|
|
|
*/ |
33
|
|
|
private $nodes = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* construct |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct() |
39
|
|
|
{ |
40
|
1 |
|
$this->nodes = [ |
41
|
|
|
'api' => Node\Api::class, |
42
|
|
|
'cluster' => Node\Cluster::class, |
43
|
|
|
'consumer' => Node\Consumer::class, |
44
|
|
|
'information' => Node\Information::class, |
45
|
|
|
'plugin' => Node\Plugin::class, |
46
|
|
|
]; |
47
|
1 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* set base uri |
51
|
|
|
* |
52
|
|
|
* @param string $baseUri |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
1 |
|
public function setBaseUri(string $baseUri): void |
57
|
|
|
{ |
58
|
1 |
|
$this->baseUri = $baseUri; |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* get base uri |
63
|
|
|
* |
64
|
|
|
* @return string $baseUri |
65
|
|
|
*/ |
66
|
1 |
|
public function getBaseUri(): string |
67
|
|
|
{ |
68
|
1 |
|
return $this->baseUri; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* add node |
73
|
|
|
* |
74
|
|
|
* @param string $name |
75
|
|
|
* @param string $class |
76
|
|
|
* |
77
|
|
|
* @return void |
78
|
|
|
* |
79
|
|
|
* @throws \RuntimeException |
80
|
|
|
* @throws \InvalidArgumentException |
81
|
|
|
*/ |
82
|
3 |
|
public function addNode(string $name, string $class): void |
83
|
|
|
{ |
84
|
3 |
|
if (!empty($this->nodes[$name])) { |
85
|
1 |
|
throw new \RuntimeException(sprintf('Node for key `%1$s` already exists', $name)); |
86
|
|
|
} |
87
|
|
|
|
88
|
2 |
|
if (!class_exists($class)) { |
89
|
1 |
|
throw new \RuntimeException(sprintf('Node class `%1$s` does not exists', $class)); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
$this->nodes[$name] = $class; |
93
|
1 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* remove node |
97
|
|
|
* |
98
|
|
|
* @param string $name |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
1 |
|
public function removeNode(string $name): void |
103
|
|
|
{ |
104
|
1 |
|
if (isset($this->nodes[$name])) { |
105
|
1 |
|
unset($this->nodes[$name]); |
106
|
|
|
} |
107
|
1 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* get node |
111
|
|
|
* |
112
|
|
|
* @param string $name |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
* |
116
|
|
|
* @throws \RuntimeException |
117
|
|
|
*/ |
118
|
2 |
|
public function getNode(string $name): string |
119
|
|
|
{ |
120
|
2 |
|
if (empty($this->nodes[$name])) { |
121
|
1 |
|
throw new \RuntimeException(sprintf('Node for key `%1$s` does not exists', $name)); |
122
|
|
|
} |
123
|
|
|
|
124
|
1 |
|
return $this->nodes[$name]; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|