PluginProbe
Depicter — Popup & Slider Builder / 1.9.6
Depicter — Popup & Slider Builder v1.9.6
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / modules / GuzzleHttp / Handler / CurlHandler.php

CurlHandler.php in Depicter — Popup & Slider Builder 1.9.6, at modules/GuzzleHttp/Handler/CurlHandler.php

50 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\GuzzleHttp\Handler;
4
5 use Depicter\GuzzleHttp\Promise\PromiseInterface;
6 use Depicter\Psr\Http\Message\RequestInterface;
7
8 /**
9 * HTTP handler that uses cURL easy handles as a transport layer.
10 *
11 * When using the CurlHandler, custom curl options can be specified as an
12 * associative array of curl option constants mapping to values in the
13 * **curl** key of the "client" key of the request.
14 *
15 * @final
16 */
17 class CurlHandler
18 {
19 /**
20 * @var CurlFactoryInterface
21 */
22 private $factory;
23
24 /**
25 * Accepts an associative array of options:
26 *
27 * - handle_factory: Optional curl factory used to create cURL handles.
28 *
29 * @param array{handle_factory?: ?CurlFactoryInterface} $options Array of options to use with the handler
30 */
31 public function __construct(array $options = [])
32 {
33 $this->factory = $options['handle_factory']
34 ?? new CurlFactory(3);
35 }
36
37 public function __invoke(RequestInterface $request, array $options): PromiseInterface
38 {
39 if (isset($options['delay'])) {
40 \usleep($options['delay'] * 1000);
41 }
42
43 $easy = $this->factory->create($request, $options);
44 \curl_exec($easy->handle);
45 $easy->errno = \curl_errno($easy->handle);
46
47 return CurlFactory::finish($this, $easy, $this->factory);
48 }
49 }
50