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 | * Builder constructor. |
||
54 | * |
||
55 | * @param \Http\Client\HttpClient|null $httpClient |
||
56 | * @param \Http\Message\UriFactory|null $uriFactory |
||
57 | * |
||
58 | * @throws \Http\Discovery\Exception\NotFoundException |
||
59 | */ |
||
60 | 21 | public function __construct( |
|
67 | |||
68 | /** |
||
69 | * Create HTTP client with specified plugins |
||
70 | * |
||
71 | * @return \Http\Client\Common\PluginClient |
||
72 | * |
||
73 | * @throws \InvalidArgumentException |
||
74 | * @throws \RuntimeException |
||
75 | */ |
||
76 | 21 | public function createConfiguredClient() |
|
94 | |||
95 | /** |
||
96 | * Add endpoint to client |
||
97 | * |
||
98 | * @param string $endpoint |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | 9 | public function withEndpoint($endpoint) |
|
108 | |||
109 | /** |
||
110 | * Add username to client |
||
111 | * |
||
112 | * @param string $username |
||
113 | * |
||
114 | * @return $this |
||
115 | */ |
||
116 | 9 | public function withUsername($username) |
|
122 | |||
123 | /** |
||
124 | * Add password to client |
||
125 | * |
||
126 | * @param string $password |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | 9 | public function withPassword($password) |
|
136 | |||
137 | /** |
||
138 | * Add username and password to client |
||
139 | * |
||
140 | * @param string $username |
||
141 | * @param string $password |
||
142 | * |
||
143 | * @return $this |
||
144 | */ |
||
145 | 9 | public function withCredentials($username, $password) |
|
151 | |||
152 | /** |
||
153 | * Add plugins to client after it has been configured |
||
154 | * |
||
155 | * @param \Http\Client\Common\Plugin|\Http\Client\Common\Plugin[] ...$plugins |
||
156 | * |
||
157 | * @return $this |
||
158 | */ |
||
159 | 3 | public function appendPlugin(Plugin ...$plugins) |
|
167 | |||
168 | /** |
||
169 | * Add plugins to client before it has been configured |
||
170 | * |
||
171 | * @param \Http\Client\Common\Plugin|\Http\Client\Common\Plugin[] ...$plugins |
||
172 | * |
||
173 | * @return $this |
||
174 | */ |
||
175 | 3 | public function prependPlugin(Plugin ...$plugins) |
|
185 | } |
||
186 |