|
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($baseUri) |
|
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() |
|
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
|
4 |
|
public function addNode($name, $class) |
|
80
|
|
|
{ |
|
81
|
4 |
|
if (!empty($this->nodes[$name])) { |
|
82
|
1 |
|
throw new \RuntimeException(sprintf('Node for key `%1$s` already exists', $name)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
3 |
|
if (!is_string($class)) { |
|
86
|
1 |
|
throw new \InvalidArgumentException('Node class should be a string'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
if (!class_exists($class)) { |
|
90
|
1 |
|
throw new \RuntimeException(sprintf('Node class `%1$s` does not exists', $class)); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
$this->nodes[$name] = $class; |
|
94
|
1 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* remove node |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $name |
|
100
|
|
|
* |
|
101
|
|
|
* @return void |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function removeNode($name) |
|
104
|
|
|
{ |
|
105
|
1 |
|
if (isset($this->nodes[$name])) { |
|
106
|
1 |
|
unset($this->nodes[$name]); |
|
107
|
|
|
} |
|
108
|
1 |
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* get node |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $name |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
2 |
|
public function getNode($name) |
|
118
|
|
|
{ |
|
119
|
2 |
|
if (empty($this->nodes[$name])) { |
|
120
|
1 |
|
throw new \RuntimeException(sprintf('Node for key `%1$s` does not exists', $name)); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
1 |
|
return $this->nodes[$name]; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|