PluginProbe
Gmail SMTP / trunk
Gmail SMTP vtrunk
1.2.3.21 1.2.3.20 trunk 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.9 1.2.0 1.2.3.14 1.2.3.15 1.2.3.16 1.2.3.18 1.2.3.5
gmail-smtp / google-api-php-client / vendor / guzzlehttp / guzzle / src / Handler / CurlHandler.php

CurlHandler.php in Gmail SMTP trunk, at google-api-php-client/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php

73 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace GuzzleHttp\Handler;
4
5 use GuzzleHttp\Promise\PromiseInterface;
6 use GuzzleHttp\TransportSharing;
7 use Psr\Http\Message\RequestInterface;
8
9 /**
10 * HTTP handler that uses cURL easy handles as a transport layer.
11 *
12 * When using the CurlHandler, custom curl options can be specified as an
13 * associative array of curl option constants mapping to values in the
14 * **curl** key of the "client" key of the request.
15 *
16 * @final
17 */
18 class CurlHandler
19 {
20 /**
21 * @var CurlFactoryInterface
22 */
23 private $factory;
24
25 /**
26 * @var CurlShareHandleState|null
27 */
28 private $shareHandleState;
29
30 /**
31 * Accepts an associative array of options:
32 *
33 * - handle_factory: Optional curl factory used to create cURL handles.
34 * - transport_sharing: Optional transport sharing mode.
35 *
36 * @param array{handle_factory?: ?CurlFactoryInterface, transport_sharing?: mixed} $options Array of options to use with the handler
37 */
38 public function __construct(array $options = [])
39 {
40 CurlShareHandleState::assertNoRequiredSharingCustomFactoryConflict($options, 'CurlHandler');
41 $transportSharing = $options['transport_sharing'] ?? null;
42 $sharingMode = CurlShareHandleState::normalizeMode($transportSharing, 'transport_sharing');
43
44 if (\array_key_exists('handle_factory', $options) && $options['handle_factory'] !== null) {
45 $this->shareHandleState = null;
46 $this->factory = $options['handle_factory'];
47
48 return;
49 }
50
51 $this->shareHandleState = $sharingMode !== TransportSharing::NONE
52 ? CurlShareHandleState::fromOption($transportSharing)
53 : null;
54
55 $this->factory = $this->shareHandleState !== null
56 ? new CurlFactory(3, $this->shareHandleState->mode, $this->shareHandleState->handle)
57 : new CurlFactory(3);
58 }
59
60 public function __invoke(RequestInterface $request, array $options): PromiseInterface
61 {
62 if (isset($options['delay'])) {
63 \usleep($options['delay'] * 1000);
64 }
65
66 $easy = $this->factory->create($request, $options);
67 \curl_exec($easy->handle);
68 $easy->errno = \curl_errno($easy->handle);
69
70 return CurlFactory::finish($this, $easy, $this->factory);
71 }
72 }
73