*/ public const CURL_FUNCTIONS = [ 'curl_init', 'curl_setopt', 'curl_setopt_array', 'curl_getinfo', 'curl_error', 'curl_strerror', 'curl_pause', 'curl_version', 'curl_multi_init', 'curl_multi_exec', 'curl_multi_add_handle', 'curl_multi_remove_handle', 'curl_multi_select', 'curl_multi_setopt', 'curl_multi_info_read', 'curl_multi_strerror', 'curl_share_init', 'curl_share_setopt', ]; /** * @param array $options Symfony's default request options, as create() takes them * @param null|\Closure(bool): bool $curl web_fetch's question, whether cURL can carry the request, asked for http (no SSL requirement); WebFetchToolkit::curlCarries() by default, a test hands in its own * @param null|\Closure(string): bool $exists whether a function can be called; function_exists() by default, a test hands in its own to stand in for disable_functions */ public static function create(array $options = [], ?\Closure $curl = null, ?\Closure $exists = null): HttpClientInterface { return ($curl ?? WebFetchToolkit::curlCarries(...))(false) && self::symfonyCurlRuns($exists ?? function_exists(...)) ? HttpClient::create($options) : new NativeHttpClient($options, 6); } /** @param \Closure(string): bool $exists */ private static function symfonyCurlRuns(\Closure $exists): bool { $needed = PHP_VERSION_ID >= 80500 ? [...self::CURL_FUNCTIONS, 'curl_share_init_persistent'] : self::CURL_FUNCTIONS; foreach ($needed as $function) { if (!$exists($function)) { return false; } } return true; } }