1 | <?php |
||
21 | final class Builder |
||
22 | { |
||
23 | use DiscoveryTrait; |
||
24 | |||
25 | /** |
||
26 | * @var \Http\Client\HttpClient|null |
||
27 | */ |
||
28 | private $httpClient; |
||
29 | |||
30 | /** |
||
31 | * @var \Http\Message\UriFactory|null |
||
32 | */ |
||
33 | private $uriFactory; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | private $plugins = []; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $username; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | private $password; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $host; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | private $path; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | private $version; |
||
64 | |||
65 | /** |
||
66 | * @param \Http\Client\HttpClient|null $httpClient |
||
67 | * @param \Http\Message\UriFactory|null $uriFactory |
||
68 | */ |
||
69 | public function __construct( |
||
76 | |||
77 | /** |
||
78 | * Create a configured HTTP client |
||
79 | * |
||
80 | * @return \Http\Client\Common\PluginClient |
||
81 | * @throws \Exception |
||
82 | */ |
||
83 | public function createConfiguredClient(): PluginClient |
||
92 | |||
93 | /** |
||
94 | * Add username to client |
||
95 | * |
||
96 | * @param string $username |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function withUsername(string $username): self |
||
106 | |||
107 | /** |
||
108 | * Add password to client |
||
109 | * |
||
110 | * @param string $password |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function withPassword(string $password): self |
||
120 | |||
121 | /** |
||
122 | * Add username and password to client |
||
123 | * |
||
124 | * @param string $username |
||
125 | * @param string $password |
||
126 | * |
||
127 | * @return \IBM\Watson\Common\HttpClient\Builder |
||
128 | */ |
||
129 | public function withCredentials(string $username, string $password): self |
||
135 | |||
136 | /** |
||
137 | * @param string $host |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function withHost(string $host): self |
||
147 | |||
148 | /** |
||
149 | * @param string $version |
||
150 | * |
||
151 | * @return $this |
||
152 | */ |
||
153 | public function withVersion($version): self |
||
159 | |||
160 | /** |
||
161 | * @param string $path |
||
162 | * |
||
163 | * @return $this |
||
164 | */ |
||
165 | public function withPath(string $path): self |
||
171 | |||
172 | /** |
||
173 | * @param \Http\Client\Common\Plugin ...$plugins |
||
174 | * |
||
175 | * @return $this |
||
176 | */ |
||
177 | public function addPlugin(Plugin ...$plugins): self |
||
185 | |||
186 | /** |
||
187 | * @return \Psr\Http\Message\UriInterface |
||
188 | */ |
||
189 | private function getHostUri(): UriInterface |
||
193 | |||
194 | /** |
||
195 | * @param string $version |
||
196 | * |
||
197 | * @return boolean |
||
198 | */ |
||
199 | private function validateVersion($version): bool |
||
205 | |||
206 | /** |
||
207 | * @return $this |
||
208 | */ |
||
209 | private function addHostPlugin(): self |
||
217 | |||
218 | /** |
||
219 | * @return $this |
||
220 | */ |
||
221 | private function addAuthenticationPlugin(): self |
||
229 | |||
230 | /** |
||
231 | * @return $this |
||
232 | * |
||
233 | * @throws InvalidArgumentException |
||
234 | */ |
||
235 | private function addVersionQueryPlugin(): self |
||
251 | |||
252 | /** |
||
253 | * @return $this |
||
254 | */ |
||
255 | private function addPathPlugin(): self |
||
263 | } |
||
264 |
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: