1 | <?php |
||
20 | final class Builder |
||
21 | { |
||
22 | use DiscoveryTrait; |
||
23 | |||
24 | /** |
||
25 | * @var \Http\Client\HttpClient|null |
||
26 | */ |
||
27 | private $httpClient; |
||
28 | |||
29 | /** |
||
30 | * @var \Http\Message\UriFactory|null |
||
31 | */ |
||
32 | private $uriFactory; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $plugins = []; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $username; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $password; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | private $host; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | private $version; |
||
58 | |||
59 | /** |
||
60 | * @param \Http\Client\HttpClient|null $httpClient |
||
61 | * @param \Http\Message\UriFactory|null $uriFactory |
||
62 | */ |
||
63 | public function __construct( |
||
70 | |||
71 | /** |
||
72 | * Create a configured HTTP client |
||
73 | * |
||
74 | * @return \Http\Client\Common\PluginClient |
||
75 | * @throws \Exception |
||
76 | */ |
||
77 | public function createConfiguredClient() |
||
86 | |||
87 | /** |
||
88 | * Add username to client |
||
89 | * |
||
90 | * @param string $username |
||
91 | * |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function withUsername($username) |
||
100 | |||
101 | /** |
||
102 | * Add password to client |
||
103 | * |
||
104 | * @param string $password |
||
105 | * |
||
106 | * @return $this |
||
107 | */ |
||
108 | public function withPassword($password) |
||
114 | |||
115 | /** |
||
116 | * Add username and password to client |
||
117 | * |
||
118 | * @param string $username |
||
119 | * @param string $password |
||
120 | * |
||
121 | * @return \IBM\Watson\Common\HttpClient\Builder |
||
122 | */ |
||
123 | public function withCredentials($username, $password) |
||
129 | |||
130 | /** |
||
131 | * @param string $host |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function withHost($host) |
||
141 | |||
142 | /** |
||
143 | * @param string $version |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function withVersion($version) |
||
153 | |||
154 | /** |
||
155 | * @param \Http\Client\Common\Plugin ...$plugins |
||
156 | * |
||
157 | * @return $this |
||
158 | */ |
||
159 | public function addPlugin(Plugin ...$plugins) |
||
167 | |||
168 | /** |
||
169 | * @return \Psr\Http\Message\UriInterface |
||
170 | */ |
||
171 | private function getHostUri() |
||
175 | |||
176 | /** |
||
177 | * @param string $version |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | private function validateVersion($version) |
||
187 | |||
188 | /** |
||
189 | * @return $this |
||
190 | */ |
||
191 | private function addHostPlugin() |
||
199 | |||
200 | |||
201 | /** |
||
202 | * @return $this |
||
203 | */ |
||
204 | private function addAuthenticationPlugin() |
||
212 | |||
213 | /** |
||
214 | * @return $this |
||
215 | */ |
||
216 | private function addVersionQueryPlugin() |
||
232 | |||
233 | /** |
||
234 | * @return $this |
||
235 | */ |
||
236 | private function addPathPlugin() |
||
242 | } |
||
243 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: