1 | <?php |
||
15 | final class Builder |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $endpoint; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $username; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $password; |
||
31 | |||
32 | /** |
||
33 | * @var \Http\Client\HttpClient |
||
34 | */ |
||
35 | private $httpClient; |
||
36 | |||
37 | /** |
||
38 | * @var \Http\Message\UriFactory |
||
39 | */ |
||
40 | private $uriFactory; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $pluginsAppend = []; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $pluginsPrepend = []; |
||
51 | |||
52 | /** |
||
53 | * @var bool |
||
54 | */ |
||
55 | private $learningOptOut; |
||
56 | |||
57 | /** |
||
58 | * Builder constructor. |
||
59 | * |
||
60 | * @param \Http\Client\HttpClient|null $httpClient |
||
61 | * @param \Http\Message\UriFactory|null $uriFactory |
||
62 | * |
||
63 | * @throws \Http\Discovery\Exception\NotFoundException |
||
64 | */ |
||
65 | public function __construct( |
||
72 | |||
73 | /** |
||
74 | * Create HTTP client with specified plugins |
||
75 | * |
||
76 | * @return \Http\Client\Common\PluginClient |
||
77 | * |
||
78 | * @throws \InvalidArgumentException |
||
79 | * @throws \RuntimeException |
||
80 | */ |
||
81 | public function createConfiguredClient() |
||
105 | |||
106 | /** |
||
107 | * Add endpoint to client |
||
108 | * |
||
109 | * @param string $endpoint |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | public function withEndpoint($endpoint) |
||
119 | |||
120 | /** |
||
121 | * Add username to client |
||
122 | * |
||
123 | * @param string $username |
||
124 | * |
||
125 | * @return $this |
||
126 | */ |
||
127 | public function withUsername($username) |
||
133 | |||
134 | /** |
||
135 | * Add password to client |
||
136 | * |
||
137 | * @param string $password |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function withPassword($password) |
||
147 | |||
148 | /** |
||
149 | * Add username and password to client |
||
150 | * |
||
151 | * @param string $username |
||
152 | * @param string $password |
||
153 | * |
||
154 | * @return $this |
||
155 | */ |
||
156 | public function withCredentials($username, $password) |
||
162 | |||
163 | /** |
||
164 | * Opt out of Watson request logging for all requests made with this client |
||
165 | * |
||
166 | * @return $this |
||
167 | */ |
||
168 | public function withLearningOptOut() |
||
174 | |||
175 | /** |
||
176 | * Add plugins to client after it has been configured |
||
177 | * |
||
178 | * @param \Http\Client\Common\Plugin|\Http\Client\Common\Plugin[] ...$plugins |
||
179 | * |
||
180 | * @return $this |
||
181 | */ |
||
182 | public function appendPlugin(Plugin ...$plugins) |
||
190 | |||
191 | /** |
||
192 | * Add plugins to client before it has been configured |
||
193 | * |
||
194 | * @param \Http\Client\Common\Plugin|\Http\Client\Common\Plugin[] ...$plugins |
||
195 | * |
||
196 | * @return $this |
||
197 | */ |
||
198 | public function prependPlugin(Plugin ...$plugins) |
||
208 | } |
||
209 |