Mercurial > hg > isophonics-drupal-site
annotate vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 namespace GuzzleHttp\Handler; |
Chris@0 | 3 |
Chris@0 | 4 use GuzzleHttp\Psr7; |
Chris@0 | 5 use Psr\Http\Message\RequestInterface; |
Chris@0 | 6 |
Chris@0 | 7 /** |
Chris@0 | 8 * HTTP handler that uses cURL easy handles as a transport layer. |
Chris@0 | 9 * |
Chris@0 | 10 * When using the CurlHandler, custom curl options can be specified as an |
Chris@0 | 11 * associative array of curl option constants mapping to values in the |
Chris@0 | 12 * **curl** key of the "client" key of the request. |
Chris@0 | 13 */ |
Chris@0 | 14 class CurlHandler |
Chris@0 | 15 { |
Chris@0 | 16 /** @var CurlFactoryInterface */ |
Chris@0 | 17 private $factory; |
Chris@0 | 18 |
Chris@0 | 19 /** |
Chris@0 | 20 * Accepts an associative array of options: |
Chris@0 | 21 * |
Chris@0 | 22 * - factory: Optional curl factory used to create cURL handles. |
Chris@0 | 23 * |
Chris@0 | 24 * @param array $options Array of options to use with the handler |
Chris@0 | 25 */ |
Chris@0 | 26 public function __construct(array $options = []) |
Chris@0 | 27 { |
Chris@0 | 28 $this->factory = isset($options['handle_factory']) |
Chris@0 | 29 ? $options['handle_factory'] |
Chris@0 | 30 : new CurlFactory(3); |
Chris@0 | 31 } |
Chris@0 | 32 |
Chris@0 | 33 public function __invoke(RequestInterface $request, array $options) |
Chris@0 | 34 { |
Chris@0 | 35 if (isset($options['delay'])) { |
Chris@0 | 36 usleep($options['delay'] * 1000); |
Chris@0 | 37 } |
Chris@0 | 38 |
Chris@0 | 39 $easy = $this->factory->create($request, $options); |
Chris@0 | 40 curl_exec($easy->handle); |
Chris@0 | 41 $easy->errno = curl_errno($easy->handle); |
Chris@0 | 42 |
Chris@0 | 43 return CurlFactory::finish($this, $easy, $this->factory); |
Chris@0 | 44 } |
Chris@0 | 45 } |