Returns an array containing CURLOPT options that can be added to
the PHP internal curl library by using curl_setopt_array

@param  array $options
@return array

@SuppressWarnings("PHPMD.StaticAccess")
483547
public static function create(array $options) {
        HashMap::assert($options, 'options');

        $filteredKeys = array_filter(array_keys($options), function ($key) {
            return strpos($key, 'CURLOPT_') === 0;
        });
        $filteredOptions = array_intersect_key($options, array_flip($filteredKeys));

        $keys = array_map(function($key) {
            return constant($key);
        }, array_keys($filteredOptions));

        $optionsWithIntKeys = array_combine($keys, array_values($filteredOptions));

        return $optionsWithIntKeys + self::$defaults;
    }
129399
public function getOptions($options)
    {
        // Add verify to options
        $options = array_merge(['verify' => $this->verify], $options);

        if ($this->async) {
            $options = array_merge(['future' => true], $options);
        }

        // merge and return
        return array_merge_recursive($this->options, $options);
    }
1111260
public function getCurlOption($option)
    {
        return isset($this->curlOptions[$option]) ? $this->curlOptions[$option] : null;
    }
118649
public function getCurlOptions()
    {
        $mandatoryOptions = array(
            CURLOPT_POST => true,
            CURLOPT_HEADER => true
        );

        $defaultOptions = array(
            CURLOPT_VERBOSE => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false
        );

        /* @noinspection AdditionOperationOnArraysInspection */
        $mergedArray = $mandatoryOptions + $this->curlOptions + $defaultOptions;

        if (strlen($this->proxyHost) > 0) {
            $proxyPort = self::DEFAULT_PROXY_PORT;
            if (strlen($this->proxyPort) > 0) {
                $proxyPort = $this->proxyPort;
            }

            $mergedArray[CURLOPT_PROXYTYPE] = $this->proxyType;
            $mergedArray[CURLOPT_PROXY] = $this->proxyHost;
            $mergedArray[CURLOPT_PROXYPORT] = $proxyPort;
        }

        return $mergedArray;
    }
905501
public static function curl(array $opts = [])
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        foreach ($opts as $key => $value) {
            curl_setopt($ch, $key, $value);
        }

        $response = curl_exec($ch);
        $request = $response !== false;
        if (!$request) {
            $response = curl_getinfo($ch);
        }
        curl_close($ch);

        return compact('request', 'response');
    }
537554
public function toCurlOptions()
    {
        $options = array();
        $options[CURLOPT_SSL_VERIFYPEER] = $this->verifyPeer;
        $options[CURLOPT_SSL_VERIFYHOST] = $this->verifyPeer ? 2 : 0;
        if ($this->caFile) {
            $options[CURLOPT_CAINFO] = $this->caFile;
        } // else: system default
        return $options;
    }
954886
protected function _init(array $curl_options)
	{
		$options = array(
			CURLOPT_SSL_VERIFYPEER => FALSE,
			CURLOPT_SSL_VERIFYHOST => FALSE,
			CURLOPT_RETURNTRANSFER => TRUE,
			CURLOPT_FOLLOWLOCATION => TRUE,
			CURLOPT_MAXREDIRS      => 10
		);

		$options += $curl_options;

		$curl = curl_init();

		curl_setopt_array($curl, $options);

		return $curl;
	}
229803
public function setOptions(array $options)
    {
        foreach ($options as $key => $value) {
            $this->options[$key] = $value;
            $value && $this->object->$key = $value;
        }

        return $this;
    }
1261107
public function curlOptSet($opt)
    {
        return isset($this->curlOpts[$opt]) || array_key_exists($opt, $this->curlOpts);
    }
237222
protected function prepareCurlOptions ( $curl_options, $extra_headers )
	{
		$hs = array();
		if (!empty($curl_options[CURLOPT_HTTPHEADER]) && is_array($curl_options[CURLOPT_HTTPHEADER]))
		{
			foreach ($curl_options[CURLOPT_HTTPHEADER] as $h)
			{
				list($opt, $val) = explode(':', $h, 2);
				$opt      = str_replace(' ', '-', ucwords(str_replace('-', ' ', $opt)));
				$hs[$opt] = $val;
			}
		}

		$curl_options[CURLOPT_HTTPHEADER] = array();
		$hs = array_merge($hs, $extra_headers);
		foreach ($hs as $h => $v)
		{
			$curl_options[CURLOPT_HTTPHEADER][] = "$h: $v";
		}
		return $curl_options;
	}
430776
final public function curlSetOptArray(array $options = array())
	{
		$this->curlFilterOpts($options);
		curl_setopt_array($this->curl_handle, $options);
		return $this;
	}
205457
public function setOptions(array $options)
    {
        $this->options = [];

        foreach ($options as $k => $v) {
            $this->addOption($k, (array)$v);
        }

        return $this;
    }
1233122
private function getRequestOptions(array $options)
    {
        $restOptions = isset($options['restOptions'])
            ? $options['restOptions']
            : $this->restOptions;
        $timeout = isset($options['requestTimeout'])
            ? $options['requestTimeout']
            : $this->requestTimeout;

        if ($timeout && !array_key_exists('timeout', $restOptions)) {
            $restOptions['timeout'] = $timeout;
        }

        return $restOptions;
    }
333225
public function option(String $options, $value) : CURL
    {
        $this->options[Helper::toConstant($options, 'CURLOPT_')] = $value;

        return $this;
    }
835884
protected function curlGetOptions($url, $options = array())
    {
        $this->debug->groupCollapsed(__METHOD__);
        $urlParts = Html::parseUrl($url);
        $optionsDefault = $this->curlOptionsDefault($url);
        $options = $this->curlOptionsNormalize($options);
        // $this->debug->log('optionsDefault', $optionsDefault);
        $options = ArrayUtil::mergeDeep($optionsDefault, $options);
        $options['CURLOPT_URL'] = \str_replace(' ', '%20', $options['CURLOPT_URL']);
        $options['CURLOPT_FOLLOWLOCATION']  = false;    // we will follow manually
        if ($options['verbose']) {
            $options['CURLOPT_VERBOSE'] = true;
            /*
            $options['tempfile'] = tempnam(\sys_get_temp_dir(), 'curl_');
            if (\is_writable($options['tempfile'])) {
                $fh = \fopen($options['tempfile'], 'w+');
                $options['CURLOPT_STDERR'] = $fh;
            }
            */
            $options['CURLINFO_HEADER_OUT'] = false;    // https://bugs.php.net/bug.php?id=65348
            $options['CURLOPT_STDERR'] = \fopen('php://temp', 'rw');
        }
        if (!empty($options['CURLOPT_PROXY']) && \in_array($urlParts['host'], array('127.0.0.1','localhost'))) {
            $this->debug->log('not using proxy for localhost');
            $options['CURLOPT_PROXY'] = false;  // formerly set to null... which no longer works
        }
        if (empty($options['CURLOPT_PROXY']) && \getenv('http_proxy')) {
            $this->debug->log('http_proxy env variable is set.... setting NO_PROXY env variable');
            \putenv('NO_PROXY='.$urlParts['host']);
        }
        $this->debug->groupEnd();
        return $options;
    }
336776
protected function prepareOptions(array $options = [])
    {
        $cookieName = time()."_".substr(md5(microtime()), 0, 5).".txt";
                
        $defaultConfig = array(
            'curl' => array(
                CURLOPT_COOKIEJAR      => $cookieName,
                CURLOPT_COOKIEFILE     => $cookieName,
            ),
        );
        $configOptions = array_merge_recursive($options, $defaultConfig);
        
        return $configOptions;
    }
1100460
private static function curl($options = array()) {
    $curlOptions = array();
    $curl = curl_init();

    $curlOptions[CURLOPT_URL] = $options["url"];
    $curlOptions[CURLOPT_RETURNTRANSFER] = true;

    if ($options["method"] != "GET") {
      if ($options["method"] != "POST") {
        $curlOptions[CURLOPT_CUSTOMREQUEST] = $options["method"];
      }
      $curlOptions[CURLOPT_POSTFIELDS] = $options["body"];
      $curlOptions[CURLOPT_POST] = true;
    } else {
      $curlOptions[CURLOPT_HTTPGET] = true;
    }

    if (Api::getEnv() == "test") {
      $curlOptions[CURLOPT_VERBOSE] = true;
      $curlOptions[CURLOPT_SSL_VERIFYHOST] = false;
      $curlOptions[CURLOPT_SSL_VERIFYPEER] = false;
    }

    $curlOptions[CURLOPT_HTTPHEADER] = $options["headers"];
    curl_setopt_array($curl, $curlOptions);

    $responseJson = curl_exec($curl);
    $responseStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    $curlErrorCode = curl_errno($curl);
    $curlErrorMessage = curl_error($curl);
    curl_close($curl);

    return array(
      "body" => $responseJson,
      "status" => $responseStatus,
      "errorCode" => $curlErrorCode,
      "errorMessage" => $curlErrorMessage
    );
  }