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
|
|
|
use Http\Message\MessageFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* client |
25
|
|
|
* |
26
|
|
|
* @author VEBER Arnaud <https://github.com/VEBERArnaud> |
27
|
|
|
*/ |
28
|
|
|
class Client |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* http client |
32
|
|
|
* @var \Http\Client\HttpClient $httpClient |
33
|
|
|
*/ |
34
|
|
|
private $httpClient = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* message factory |
38
|
|
|
* @var \Http\Message\MessageFactory $messageFactory |
39
|
|
|
*/ |
40
|
|
|
private $messageFactory = null; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* plugins |
44
|
|
|
* @var array $plugins |
45
|
|
|
*/ |
46
|
|
|
private $plugins = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* constructor |
50
|
|
|
* |
51
|
|
|
* @param string $baseUri |
52
|
|
|
* @param \Http\Client\HttpClient $httpClient |
53
|
|
|
*/ |
54
|
|
|
public function __construct($baseUri, HttpClient $httpClient = null) |
55
|
|
|
{ |
56
|
|
|
$this->httpClient = $httpClient ?: HttpClientDiscovery::find(); |
57
|
|
|
$this->messageFactory = MessageFactoryDiscovery::find(); |
58
|
|
|
|
59
|
|
|
$this->addPlugin( |
60
|
|
|
new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($baseUri)) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* api |
66
|
|
|
* |
67
|
|
|
* @param string $name |
68
|
|
|
* |
69
|
|
|
* @return \Unikorp\KongAdminApi\ApiInterface |
70
|
|
|
* |
71
|
|
|
* @throws \InvalidArgumentException |
72
|
|
|
*/ |
73
|
|
|
public function api($name) |
74
|
|
|
{ |
75
|
|
|
switch ($name) { |
76
|
|
|
default: |
|
|
|
|
77
|
|
|
throw new \InvalidArgumentException(sprintf('Undefined api instance called: %s', $name)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* add plugin |
83
|
|
|
* |
84
|
|
|
* @param \Http\Client\Common\Plugin $plugin |
85
|
|
|
* |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
public function addPlugin(Plugin $plugin) |
89
|
|
|
{ |
90
|
|
|
$this->plugins[] = $plugin; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* get http client |
95
|
|
|
* |
96
|
|
|
* @return \Http\Client\Common\HttpMethodsClient |
97
|
|
|
*/ |
98
|
|
|
public function getHttpClient() |
99
|
|
|
{ |
100
|
|
|
return new HttpMethodsClient( |
101
|
|
|
new PluginClient($this->httpClient, $this->plugins), |
102
|
|
|
$this->messageFactory |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.