• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

voku / httpful / 42395164963

07 Nov 2026 05:12PM UTC coverage: 95.599% (-0.2%) from 95.82%
42395164963

push

github

web-flow
Update dependency psr/http-factory to 1.1.* (#38)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

2737 of 2863 relevant lines covered (95.6%)

59.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.16
/src/Httpful/ClientMulti.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Httpful;
6

7
use Httpful\Curl\MultiCurl;
8
use Psr\Http\Message\RequestInterface;
9

10
class ClientMulti
11
{
12
    /**
13
     * @var MultiCurl
14
     */
15
    public $curlMulti;
16

17
    /**
18
     * @param callable|null $onSuccessCallback
19
     * @param callable|null $onCompleteCallback
20
     */
21
    public function __construct($onSuccessCallback = null, $onCompleteCallback = null)
22
    {
23
        $this->curlMulti = (new Request())
25 ✔
24
            ->initMulti($onSuccessCallback, $onCompleteCallback);
25 ✔
25
    }
26

27
    /**
28
     * @return void
29
     */
30
    public function start()
31
    {
32
        $this->curlMulti->start();
4 ✔
33
    }
34

35
    /**
36
     * @param string                       $uri
37
     * @param array<string|int, mixed>|null $params
38
     * @param string                       $mime
39
     *
40
     * @return $this
41
     */
42
    public function add_delete(string $uri, ?array $params = null, string $mime = Mime::JSON)
43
    {
44
        $request = Request::delete($uri, $params, $mime);
1 ✔
45
        $curl = $request->_curlPrep()->_curl();
1 ✔
46

47
        if ($curl) {
1 ✔
48
            $curl->request = $request;
1 ✔
49
            $this->curlMulti->addCurl($curl);
1 ✔
50
        }
51

52
        return $this;
1 ✔
53
    }
54

55
    /**
56
     * @param string $uri
57
     * @param string $file_path
58
     *
59
     * @return $this
60
     */
61
    public function add_download(string $uri, $file_path)
62
    {
63
        $request = Request::download($uri, $file_path);
1 ✔
64
        $curl = $request->_curlPrep()->_curl();
1 ✔
65

66
        if ($curl) {
1 ✔
67
            $curl->request = $request;
1 ✔
68
            $this->curlMulti->addCurl($curl);
1 ✔
69
        }
70

71
        return $this;
1 ✔
72
    }
73

74
    /**
75
     * @param string                       $uri
76
     * @param array<string|int, mixed>|null $params
77
     * @param string|null                  $mime
78
     *
79
     * @return $this
80
     */
81
    public function add_html(string $uri, ?array $params = null, $mime = Mime::HTML)
82
    {
83
        $request = Request::get($uri, $params, $mime)->followRedirects();
1 ✔
84
        $curl = $request->_curlPrep()->_curl();
1 ✔
85

86
        if ($curl) {
1 ✔
87
            $curl->request = $request;
1 ✔
88
            $this->curlMulti->addCurl($curl);
1 ✔
89
        }
90

91
        return $this;
1 ✔
92
    }
93

94
    /**
95
     * @param string                       $uri
96
     * @param array<string|int, mixed>|null $params
97
     * @param string|null                  $mime
98
     *
99
     * @return $this
100
     */
101
    public function add_get(string $uri, ?array $params = null, $mime = Mime::PLAIN)
102
    {
103
        $request = Request::get($uri, $params, $mime)->followRedirects();
4 ✔
104
        $curl = $request->_curlPrep()->_curl();
4 ✔
105

106
        if ($curl) {
4 ✔
107
            $curl->request = $request;
4 ✔
108
            $this->curlMulti->addCurl($curl);
4 ✔
109
        }
110

111
        return $this;
4 ✔
112
    }
113

114
    /**
115
     * @param string                       $uri
116
     * @param array<string|int, mixed>|null $params
117
     *
118
     * @return $this
119
     */
120
    public function add_get_dom(string $uri, ?array $params = null)
121
    {
122
        $request = Request::get($uri, $params, Mime::HTML)->followRedirects();
1 ✔
123
        $curl = $request->_curlPrep()->_curl();
1 ✔
124

125
        if ($curl) {
1 ✔
126
            $curl->request = $request;
1 ✔
127
            $this->curlMulti->addCurl($curl);
1 ✔
128
        }
129

130
        return $this;
1 ✔
131
    }
132

133
    /**
134
     * @param string                       $uri
135
     * @param array<string|int, mixed>|null $params
136
     *
137
     * @return $this
138
     */
139
    public function add_get_form(string $uri, ?array $params = null)
140
    {
141
        $request = Request::get($uri, $params, Mime::FORM)->followRedirects();
1 ✔
142
        $curl = $request->_curlPrep()->_curl();
1 ✔
143

144
        if ($curl) {
1 ✔
145
            $curl->request = $request;
1 ✔
146
            $this->curlMulti->addCurl($curl);
1 ✔
147
        }
148

149
        return $this;
1 ✔
150
    }
151

152
    /**
153
     * @param string                       $uri
154
     * @param array<string|int, mixed>|null $params
155
     *
156
     * @return $this
157
     */
158
    public function add_get_json(string $uri, ?array $params = null)
159
    {
160
        $request = Request::get($uri, $params, Mime::JSON)->followRedirects();
1 ✔
161
        $curl = $request->_curlPrep()->_curl();
1 ✔
162

163
        if ($curl) {
1 ✔
164
            $curl->request = $request;
1 ✔
165
            $this->curlMulti->addCurl($curl);
1 ✔
166
        }
167

168
        return $this;
1 ✔
169
    }
170

171
    /**
172
     * @param string                       $uri
173
     * @param array<string|int, mixed>|null $params
174
     *
175
     * @return $this
176
     */
177
    public function get_xml(string $uri, ?array $params = null)
178
    {
179
        $request = Request::get($uri, $params, Mime::XML)->followRedirects();
1 ✔
180
        $curl = $request->_curlPrep()->_curl();
1 ✔
181

182
        if ($curl) {
1 ✔
183
            $curl->request = $request;
1 ✔
184
            $this->curlMulti->addCurl($curl);
1 ✔
185
        }
186

187
        return $this;
1 ✔
188
    }
189

190
    /**
191
     * @param string $uri
192
     *
193
     * @return $this
194
     */
195
    public function add_head(string $uri)
196
    {
197
        $request = Request::head($uri)->followRedirects();
1 ✔
198
        $curl = $request->_curlPrep()->_curl();
1 ✔
199

200
        if ($curl) {
1 ✔
201
            $curl->request = $request;
1 ✔
202
            $this->curlMulti->addCurl($curl);
1 ✔
203
        }
204

205
        return $this;
1 ✔
206
    }
207

208
    /**
209
     * @param string $uri
210
     *
211
     * @return $this
212
     */
213
    public function add_options(string $uri)
214
    {
215
        $request = Request::options($uri);
1 ✔
216
        $curl = $request->_curlPrep()->_curl();
1 ✔
217

218
        if ($curl) {
1 ✔
219
            $curl->request = $request;
1 ✔
220
            $this->curlMulti->addCurl($curl);
1 ✔
221
        }
222

223
        return $this;
1 ✔
224
    }
225

226
    /**
227
     * @param string     $uri
228
     * @param mixed|null $payload
229
     * @param string     $mime
230
     *
231
     * @return $this
232
     */
233
    public function add_patch(string $uri, $payload = null, string $mime = Mime::PLAIN)
234
    {
235
        $request = Request::patch($uri, $payload, $mime);
1 ✔
236
        $curl = $request->_curlPrep()->_curl();
1 ✔
237

238
        if ($curl) {
1 ✔
239
            $curl->request = $request;
1 ✔
240
            $this->curlMulti->addCurl($curl);
1 ✔
241
        }
242

243
        return $this;
1 ✔
244
    }
245

246
    /**
247
     * Queue a QUERY request (RFC 10008).
248
     *
249
     * @param string     $uri
250
     * @param mixed|null $payload
251
     * @param string     $mime
252
     *
253
     * @return $this
254
     */
255
    public function add_query(string $uri, $payload = null, string $mime = Mime::PLAIN)
256
    {
257
        $request = Request::query($uri, $payload, $mime);
×
258
        $curl = $request->_curlPrep()->_curl();
×
259

260
        if ($curl) {
×
261
            $curl->request = $request;
×
262
            $this->curlMulti->addCurl($curl);
×
263
        }
264

265
        return $this;
×
266
    }
267

268
    /**
269
     * @param string     $uri
270
     * @param mixed|null $payload
271
     * @param string     $mime
272
     *
273
     * @return $this
274
     */
275
    public function add_post(string $uri, $payload = null, string $mime = Mime::PLAIN)
276
    {
277
        $request = Request::post($uri, $payload, $mime)->followRedirects();
1 ✔
278
        $curl = $request->_curlPrep()->_curl();
1 ✔
279

280
        if ($curl) {
1 ✔
281
            $curl->request = $request;
1 ✔
282
            $this->curlMulti->addCurl($curl);
1 ✔
283
        }
284

285
        return $this;
1 ✔
286
    }
287

288
    /**
289
     * @param string     $uri
290
     * @param mixed|null $payload
291
     *
292
     * @return $this
293
     */
294
    public function add_post_dom(string $uri, $payload = null)
295
    {
296
        $request = Request::post($uri, $payload, Mime::HTML)->followRedirects();
1 ✔
297
        $curl = $request->_curlPrep()->_curl();
1 ✔
298

299
        if ($curl) {
1 ✔
300
            $curl->request = $request;
1 ✔
301
            $this->curlMulti->addCurl($curl);
1 ✔
302
        }
303

304
        return $this;
1 ✔
305
    }
306

307
    /**
308
     * @param string     $uri
309
     * @param mixed|null $payload
310
     *
311
     * @return $this
312
     */
313
    public function add_post_form(string $uri, $payload = null)
314
    {
315
        $request = Request::post($uri, $payload, Mime::FORM)->followRedirects();
1 ✔
316
        $curl = $request->_curlPrep()->_curl();
1 ✔
317

318
        if ($curl) {
1 ✔
319
            $curl->request = $request;
1 ✔
320
            $this->curlMulti->addCurl($curl);
1 ✔
321
        }
322

323
        return $this;
1 ✔
324
    }
325

326
    /**
327
     * @param string     $uri
328
     * @param mixed|null $payload
329
     *
330
     * @return $this
331
     */
332
    public function add_post_json(string $uri, $payload = null)
333
    {
334
        $request = Request::post($uri, $payload, Mime::JSON)->followRedirects();
1 ✔
335
        $curl = $request->_curlPrep()->_curl();
1 ✔
336

337
        if ($curl) {
1 ✔
338
            $curl->request = $request;
1 ✔
339
            $this->curlMulti->addCurl($curl);
1 ✔
340
        }
341

342
        return $this;
1 ✔
343
    }
344

345
    /**
346
     * @param string     $uri
347
     * @param mixed|null $payload
348
     *
349
     * @return $this
350
     */
351
    public function add_post_xml(string $uri, $payload = null)
352
    {
353
        $request = Request::post($uri, $payload, Mime::XML)->followRedirects();
1 ✔
354
        $curl = $request->_curlPrep()->_curl();
1 ✔
355

356
        if ($curl) {
1 ✔
357
            $curl->request = $request;
1 ✔
358
            $this->curlMulti->addCurl($curl);
1 ✔
359
        }
360

361
        return $this;
1 ✔
362
    }
363

364
    /**
365
     * @param string     $uri
366
     * @param mixed|null $payload
367
     * @param string     $mime
368
     *
369
     * @return $this
370
     */
371
    public function add_put(string $uri, $payload = null, string $mime = Mime::PLAIN)
372
    {
373
        $request = Request::put($uri, $payload, $mime);
1 ✔
374
        $curl = $request->_curlPrep()->_curl();
1 ✔
375

376
        if ($curl) {
1 ✔
377
            $curl->request = $request;
1 ✔
378
            $this->curlMulti->addCurl($curl);
1 ✔
379
        }
380

381
        return $this;
1 ✔
382
    }
383

384
    /**
385
     * @param Request|RequestInterface $request
386
     *
387
     * @return $this
388
     */
389
    public function add_request(RequestInterface $request)
390
    {
391
        if (!$request instanceof Request) {
7 ✔
392
            /** @noinspection PhpSillyAssignmentInspection - helper for PhpStorm */
393
            /** @var RequestInterface $request */
394
            $request = $request;
1 ✔
395

396
            /** @var Request $requestNew */
397
            $requestNew = Request::{$request->getMethod()}($request->getUri());
1 ✔
398
            $requestNew->withHeaders($request->getHeaders());
1 ✔
399
            $requestNew->withProtocolVersion($request->getProtocolVersion());
1 ✔
400
            $requestNew->withBody($request->getBody());
1 ✔
401
            $requestNew->withRequestTarget($request->getRequestTarget());
1 ✔
402

403
            $request = $requestNew;
1 ✔
404
        }
405

406
        $curl = $request->_curlPrep()->_curl();
7 ✔
407

408
        if ($curl) {
7 ✔
409
            $curl->request = $request;
7 ✔
410
            $this->curlMulti->addCurl($curl);
7 ✔
411
        }
412

413
        return $this;
7 ✔
414
    }
415
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc