PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / vendor / _scoped / guzzlehttp / guzzle / src / Handler / CurlHandler.php

CurlHandler.php in Metricool – Social media and site statistics 2.1.1, at vendor/_scoped/guzzlehttp/guzzle/src/Handler/CurlHandler.php

71 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Metricool\Vendor\GuzzleHttp\Handler;
4
5 use Metricool\Vendor\GuzzleHttp\Promise\PromiseInterface;
6 use Metricool\Vendor\GuzzleHttp\TransportSharing;
7 use Metricool\Vendor\Psr\Http\Message\RequestInterface;
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 private const KNOWN_CONSTRUCTOR_OPTIONS = ['handle_factory' => \true, 'transport_sharing' => \true];
20 /**
21 * @var CurlFactoryInterface
22 */
23 private $factory;
24 /**
25 * @var CurlShareHandleState|null
26 */
27 private $shareHandleState;
28 /**
29 * Accepts an associative array of options:
30 *
31 * - handle_factory: Optional curl factory used to create cURL handles.
32 * - transport_sharing: Optional transport sharing mode.
33 *
34 * @param array{handle_factory?: ?CurlFactoryInterface, transport_sharing?: mixed} $options Array of options to use with the handler
35 */
36 public function __construct(array $options = [])
37 {
38 foreach ($options as $name => $_) {
39 if (!isset(self::KNOWN_CONSTRUCTOR_OPTIONS[$name])) {
40 \Metricool\Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.14', \sprintf('The "%s" CurlHandler constructor option is unknown; guzzlehttp/guzzle 8.0 will reject unknown constructor options.', (string) $name));
41 }
42 }
43 CurlShareHandleState::assertNoRequiredSharingCustomFactoryConflict($options, 'CurlHandler');
44 $transportSharing = $options['transport_sharing'] ?? null;
45 $sharingMode = CurlShareHandleState::normalizeMode($transportSharing, 'transport_sharing');
46 if (\array_key_exists('handle_factory', $options) && $options['handle_factory'] !== null) {
47 $this->shareHandleState = null;
48 $this->factory = $options['handle_factory'];
49 return;
50 }
51 $this->shareHandleState = $sharingMode !== TransportSharing::NONE ? CurlShareHandleState::fromOption($transportSharing) : null;
52 $this->factory = $this->shareHandleState !== null ? new CurlFactory(3, $this->shareHandleState->mode, $this->shareHandleState) : new CurlFactory(3);
53 }
54 public function __invoke(RequestInterface $request, array $options): PromiseInterface
55 {
56 HostValidator::assertRequestHost($request);
57 if (isset($options['delay'])) {
58 \usleep($options['delay'] * 1000);
59 }
60 // A Multiplexing::NONE request option holds unconditionally here:
61 // transport sharing never shares the connection cache on this
62 // branch, and nothing else executes during the blocking curl_exec(),
63 // so the transfer cannot share its connection with a concurrent
64 // transfer.
65 $easy = $this->factory->create($request, $options);
66 \curl_exec($easy->handle);
67 $easy->errno = \curl_errno($easy->handle);
68 return CurlFactory::finish($this, $easy, $this->factory);
69 }
70 }
71