|
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 Http\Client\Common\HttpMethodsClient; |
|
15
|
|
|
use Http\Client\Common\Plugin; |
|
16
|
|
|
use Http\Client\Common\PluginClient; |
|
17
|
|
|
use Http\Client\HttpClient; |
|
18
|
|
|
use Http\Discovery\HttpClientDiscovery; |
|
19
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
|
20
|
|
|
use Http\Discovery\UriFactoryDiscovery; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* client |
|
24
|
|
|
* |
|
25
|
|
|
* @author VEBER Arnaud <https://github.com/VEBERArnaud> |
|
26
|
|
|
*/ |
|
27
|
|
|
class Client |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* configurator |
|
31
|
|
|
* @var \Unikorp\KongAdminApi\ConfiguratorInterface $configurator |
|
32
|
|
|
*/ |
|
33
|
|
|
private $configurator = null; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* http client |
|
37
|
|
|
* @var \Http\Client\HttpClient $httpClient |
|
38
|
|
|
*/ |
|
39
|
|
|
private $httpClient = null; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* message factory |
|
43
|
|
|
* @var \Http\Message\MessageFactory $messageFactory |
|
44
|
|
|
*/ |
|
45
|
|
|
private $messageFactory = null; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* plugins |
|
49
|
|
|
* @var array $plugins |
|
50
|
|
|
*/ |
|
51
|
|
|
private $plugins = []; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* constructor |
|
55
|
|
|
* |
|
56
|
|
|
* @param \Unikorm\KongAdminApi\ConfiguratorInterface $configurator |
|
57
|
|
|
* @param \Http\Client\HttpClient $httpClient |
|
58
|
|
|
*/ |
|
59
|
3 |
|
public function __construct(ConfiguratorInterface $configurator, HttpClient $httpClient = null) |
|
60
|
|
|
{ |
|
61
|
3 |
|
$this->configurator = $configurator; |
|
62
|
|
|
|
|
63
|
3 |
|
$this->httpClient = $httpClient ?: HttpClientDiscovery::find(); |
|
64
|
3 |
|
$this->messageFactory = MessageFactoryDiscovery::find(); |
|
65
|
|
|
|
|
66
|
3 |
|
$this->plugins[] = new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($configurator->getBaseUri())); |
|
67
|
3 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* get node |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $name |
|
73
|
|
|
* |
|
74
|
|
|
* @return \Unikorp\KongAdminApi\NodeInterface |
|
75
|
|
|
*/ |
|
76
|
6 |
|
public function getNode($name) |
|
77
|
|
|
{ |
|
78
|
6 |
|
$node = $this->configurator->getNode($name); |
|
79
|
|
|
|
|
80
|
5 |
|
return new $node($this); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* add plugin |
|
85
|
|
|
* |
|
86
|
|
|
* @param \Http\Client\Common\Plugin $plugin |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function addPlugin(Plugin $plugin) |
|
91
|
|
|
{ |
|
92
|
1 |
|
$this->plugins[] = $plugin; |
|
93
|
1 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* get http client |
|
97
|
|
|
* |
|
98
|
|
|
* @return \Http\Client\Common\HttpMethodsClient |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function getHttpClient() |
|
101
|
|
|
{ |
|
102
|
1 |
|
return new HttpMethodsClient( |
|
103
|
1 |
|
new PluginClient($this->httpClient, $this->plugins), |
|
104
|
1 |
|
$this->messageFactory |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|