Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Utils.php

function Utils::chooseHandler

Chooses and creates a default handler to use based on the environment.

The returned handler is not wrapped by any default middlewares.

Return value

callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system.

Throws

\RuntimeException if no viable Handler is available.

3 calls to Utils::chooseHandler()
choose_handler in vendor/guzzlehttp/guzzle/src/functions.php
Chooses and creates a default handler to use based on the environment.
Client::buildClient in vendor/php-http/guzzle7-adapter/src/Client.php
Build the Guzzle client instance.
HandlerStack::create in vendor/guzzlehttp/guzzle/src/HandlerStack.php
Creates a default handler stack that can be used by clients.

File

vendor/guzzlehttp/guzzle/src/Utils.php, line 86

Class

Utils

Namespace

GuzzleHttp

Code

public static function chooseHandler() : callable {
    $handler = null;
    if (\defined('CURLOPT_CUSTOMREQUEST') && \function_exists('curl_version') && version_compare(curl_version()['version'], '7.21.2') >= 0) {
        if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
            $handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler());
        }
        elseif (\function_exists('curl_exec')) {
            $handler = new CurlHandler();
        }
        elseif (\function_exists('curl_multi_exec')) {
            $handler = new CurlMultiHandler();
        }
    }
    if (\ini_get('allow_url_fopen')) {
        $handler = $handler ? Proxy::wrapStreaming($handler, new StreamHandler()) : new StreamHandler();
    }
    elseif (!$handler) {
        throw new \RuntimeException('GuzzleHttp requires cURL, the allow_url_fopen ini setting, or a custom HTTP handler.');
    }
    return $handler;
}
RSS feed
Powered by Drupal