Debian Codegraph @

lib/3rdParty/composer/symfony/http-client/HttpOptions.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 Symfony\Component\HttpClient;
13
14 use Symfony\Contracts\HttpClient\HttpClientInterface;
15
16 /**
17 * A helper providing autocompletion for available options.
18 *
19 * @see HttpClientInterface for a description of each options.
20 *
21 * @author Nicolas Grekas <[email protected]>
22 */
23 class HttpOptions
24 {
25 private array $options = [];
26
27 public function toArray(): array
28 {
29 return $this->options;
30 }
31
32 /**
33 * @return $this
34 */
35 public function setAuthBasic(string $user, #[\SensitiveParameter] string $password = ''): static
36 {
37 $this->options['auth_basic'] = $user;
38
39 if ('' !== $password) {
40 $this->options['auth_basic'] .= ':'.$password;
41 }
42
43 return $this;
44 }
45
46 /**
47 * @return $this
48 */
49 public function setAuthBearer(#[\SensitiveParameter] string $token): static
50 {
51 $this->options['auth_bearer'] = $token;
52
53 return $this;
54 }
55
56 /**
57 * @return $this
58 */
59 public function setQuery(array $query): static
60 {
61 $this->options['query'] = $query;
62
63 return $this;
64 }
65
66 /**
67 * @return $this
68 */
69 public function setHeader(string $key, string $value): static
70 {
71 $this->options['headers'][$key] = $value;
72
73 return $this;
74 }
75
76 /**
77 * @return $this
78 */
79 public function setHeaders(iterable $headers): static
80 {
81 $this->options['headers'] = $headers;
82
83 return $this;
84 }
85
86 /**
87 * @param array|string|resource|\Traversable|\Closure $body
88 *
89 * @return $this
90 */
91 public function setBody(mixed $body): static
92 {
93 $this->options['body'] = $body;
94
95 return $this;
96 }
97
98 /**
99 * @return $this
100 */
101 public function setJson(mixed $json): static
102 {
103 $this->options['json'] = $json;
104
105 return $this;
106 }
107
108 /**
109 * @return $this
110 */
111 public function setUserData(mixed $data): static
112 {
113 $this->options['user_data'] = $data;
114
115 return $this;
116 }
117
118 /**
119 * @return $this
120 */
121 public function setMaxRedirects(int $max): static
122 {
123 $this->options['max_redirects'] = $max;
124
125 return $this;
126 }
127
128 /**
129 * @return $this
130 */
131 public function setHttpVersion(string $version): static
132 {
133 $this->options['http_version'] = $version;
134
135 return $this;
136 }
137
138 /**
139 * @return $this
140 */
141 public function setBaseUri(string $uri): static
142 {
143 $this->options['base_uri'] = $uri;
144
145 return $this;
146 }
147
148 /**
149 * @return $this
150 */
151 public function setVars(array $vars): static
152 {
153 $this->options['vars'] = $vars;
154
155 return $this;
156 }
157
158 /**
159 * @return $this
160 */
161 public function buffer(bool $buffer): static
162 {
163 $this->options['buffer'] = $buffer;
164
165 return $this;
166 }
167
168 /**
169 * @param callable(int, int, array, \Closure|null=):void $callback
170 *
171 * @return $this
172 */
173 public function setOnProgress(callable $callback): static
174 {
175 $this->options['on_progress'] = $callback;
176
177 return $this;
178 }
179
180 /**
181 * @return $this
182 */
183 public function resolve(array $hostIps): static
184 {
185 $this->options['resolve'] = $hostIps;
186
187 return $this;
188 }
189
190 /**
191 * @return $this
192 */
193 public function setProxy(string $proxy): static
194 {
195 $this->options['proxy'] = $proxy;
196
197 return $this;
198 }
199
200 /**
201 * @return $this
202 */
203 public function setNoProxy(string $noProxy): static
204 {
205 $this->options['no_proxy'] = $noProxy;
206
207 return $this;
208 }
209
210 /**
211 * @return $this
212 */
213 public function setTimeout(float $timeout): static
214 {
215 $this->options['timeout'] = $timeout;
216
217 return $this;
218 }
219
220 /**
221 * @return $this
222 */
223 public function setMaxDuration(float $maxDuration): static
224 {
225 $this->options['max_duration'] = $maxDuration;
226
227 return $this;
228 }
229
230 /**
231 * @return $this
232 */
233 public function bindTo(string $bindto): static
234 {
235 $this->options['bindto'] = $bindto;
236
237 return $this;
238 }
239
240 /**
241 * @return $this
242 */
243 public function verifyPeer(bool $verify): static
244 {
245 $this->options['verify_peer'] = $verify;
246
247 return $this;
248 }
249
250 /**
251 * @return $this
252 */
253 public function verifyHost(bool $verify): static
254 {
255 $this->options['verify_host'] = $verify;
256
257 return $this;
258 }
259
260 /**
261 * @return $this
262 */
263 public function setCaFile(string $cafile): static
264 {
265 $this->options['cafile'] = $cafile;
266
267 return $this;
268 }
269
270 /**
271 * @return $this
272 */
273 public function setCaPath(string $capath): static
274 {
275 $this->options['capath'] = $capath;
276
277 return $this;
278 }
279
280 /**
281 * @return $this
282 */
283 public function setLocalCert(string $cert): static
284 {
285 $this->options['local_cert'] = $cert;
286
287 return $this;
288 }
289
290 /**
291 * @return $this
292 */
293 public function setLocalPk(string $pk): static
294 {
295 $this->options['local_pk'] = $pk;
296
297 return $this;
298 }
299
300 /**
301 * @return $this
302 */
303 public function setPassphrase(string $passphrase): static
304 {
305 $this->options['passphrase'] = $passphrase;
306
307 return $this;
308 }
309
310 /**
311 * @return $this
312 */
313 public function setCiphers(string $ciphers): static
314 {
315 $this->options['ciphers'] = $ciphers;
316
317 return $this;
318 }
319
320 /**
321 * @return $this
322 */
323 public function setPeerFingerprint(string|array $fingerprint): static
324 {
325 $this->options['peer_fingerprint'] = $fingerprint;
326
327 return $this;
328 }
329
330 /**
331 * @return $this
332 */
333 public function capturePeerCertChain(bool $capture): static
334 {
335 $this->options['capture_peer_cert_chain'] = $capture;
336
337 return $this;
338 }
339
340 /**
341 * @return $this
342 */
343 public function setExtra(string $name, mixed $value): static
344 {
345 $this->options['extra'][$name] = $value;
346
347 return $this;
348 }
349 }