Execute cURL session.

@param array $options

@throws RuntimeException
@throws TransferException

@return array
340379
protected function execute(array $options = [])
    {
        $session = $this->createSession();
        $result = [];

        try {
            if ($session->open() === false) {
                throw new RuntimeException('Cannot initialize a cURL session');
            }

            $session->setOptions($options + $this->options);

            $result = $session->execute();

            if ($result === false) {
                throw new TransferException($session->getErrorMessage(), $session->getErrorCode());
            }

            $headerSize = $session->getInfo(CURLINFO_HEADER_SIZE);

            if (strlen($result) < $headerSize) {
                throw new TransferException(
                    'Header size(' . $headerSize . ') does not match result: ' . $result
                );
            }

            $result = [
                substr($result, $headerSize) ?: null,
                substr($result, 0, $headerSize) ?: null,
            ];
        } finally {
            $session->close();
        }

        return $result;
    }
592204
private function initCurl(array $curlOptions)
    {
        $curlResource = curl_init();
        foreach ($curlOptions as $option => $value) {
            curl_setopt($curlResource, $option, $value);
        }

        return $curlResource;
    }
331453
public function connect(array $options = [])
    {
        $config = $this->_parseConfig($options);
        try {
            $this->client = new SoapClient($this->getConfig('wsdl'), $config);
        } catch (SoapFault $fault) {
            $this->handleError($fault->faultstring);
        }

        if ($this->client) {
            $this->connected = true;
        }

        return $this->connected;
    }
1299521
private function doValidateOptions(array $options = []): array
    {
        if (
            isset($this->options['curl'], $options['curl']) &&
            \is_array($this->options['curl']) &&
            \is_array($options['curl'])
        ) {
            $parameters['curl'] = \array_replace($this->options['curl'], $options['curl']);
        }

        $options = \array_replace($this->options, $options);

        foreach (static::$types as $k => $v) {
            $type = \gettype($options[$k]);
            $v = (array) $v;

            $checked = false;
            foreach ($v as $t) {
                if ($t === $type || ($t === 'callable' && \is_callable($options[$k]))) {
                    $checked = true;
                    break;
                }
            }

            if (!$checked) {
                $should = \implode(', ', $v);
                throw new InvalidArgumentException("'$k' options should be '$should', but get '$type'");
            }
        }

        return $options;
    }
754065
protected function send(array $options = []): StreamInterface
    {
        try {
            $response = $this->client->post(
                $this->getUrl(),
                $options
            );
        } catch (RequestException $requestException) {
            throw new ComputopApiHttpRequestException(
                $requestException->getMessage(),
                $requestException->getCode(),
                $requestException
            );
        }

        return $response->getBody();
    }
1325151
protected function executeCurl($url, array $options = array())
    {
        $session = curl_init($url);

        if (count($options)) {
            curl_setopt_array($session, $options);
        }

        $response = curl_exec($session);

        $error = false;
        $info = curl_getinfo($session);
        if ($response === false) {
            $error = curl_error($session);
        }

        curl_close($session);

        return array($response, $info, $error);
    }
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;
    }
608230
protected function exec($options)
    {  
        $method = key($options);
        $requestPath = reset($options);
        $verb = self::$verbArray[$method];
        
        $headers = $this->getArrayValue($options, 'headers');
        $url_query = $this->getArrayValue($options, 'url_query');
        $formData = $this->getArrayValue($options, 'form_data');
        $jsonData = $this->getArrayValue($options, 'json_data');
        

        $defaultHttpParams = self::$defaultParams;
        $connectionParams = array_merge($defaultHttpParams, $this->customParams);
        $query = '';

        if ($url_query > 0) {
            $query = http_build_query($url_query);
        }
        
        $address = $this->getArrayValue($connectionParams, 'address');
        $uri = $address . $requestPath;
        if ($query != '') {
            if (parse_url($uri, PHP_URL_QUERY)) {
                $uri .= '&' . $query;
            } else {
                $uri .= '?' . $query;
            }
        }

        $connect = $this->getHttpRequest();
        $connect->setOption(CURLOPT_URL, $uri);
        if ($userAgent = $this->getArrayValue($connectionParams, 'user_agent')) {
            $connect->setOption(CURLOPT_USERAGENT, $userAgent);
        }
        $connect->setOption(CURLOPT_RETURNTRANSFER, true);
        $connect->setOption(CURLOPT_CUSTOMREQUEST, $verb);
        
        $this->setHeaders($connect, $headers);
        $proxyAddress = $this->getArrayValue($connectionParams, 'proxy_addr');
        $proxyPort = $this->getArrayValue($connectionParams, 'proxy_port');
        if (!empty($proxyAddress)) {
            $connect->setOption(CURLOPT_PROXY, $proxyAddress);
            $connect->setOption(CURLOPT_PROXYPORT, $proxyPort);
        }
        if ($useSsl = $this->getArrayValue($connectionParams, 'use_ssl')) {
            $connect->setOption(CURLOPT_SSL_VERIFYPEER, $useSsl);
        }
        if ($sslVersion = $this->getArrayValue($connectionParams, 'ssl_version')) {
            $connect->setOption(CURLOPT_SSLVERSION, $sslVersion);
        }
        if ($verifyMode = $this->getArrayValue($connectionParams, 'verify_mode')) {
            $connect->setOption(CURLOPT_SSL_VERIFYHOST, $verifyMode);
        }
        if ($caFile = $this->getArrayValue($connectionParams, 'ca_file')) {
            $connect->setOption(CURLOPT_CAPATH, $caFile);
        }
        
        $connect->setOption(CURLOPT_FOLLOWLOCATION, true);

        if ($formData) {
            $this->setData($connect, $formData);
        }
        if ($jsonData) {
            $this->setData($connect, $jsonData, "application/json");
        }
 
        $apiResult = $connect->execute();
        $apiHttpCode = $connect->getInfo(CURLINFO_HTTP_CODE);
        
        if ($apiResult === false) {
            throw new Exception ($connect->error());
        }
        
        $response['response'] = [];
        
        if ($apiHttpCode != "200" && $apiHttpCode != "201") {
            error_log($apiResult);
        }
        
        $response['response'] = json_decode($apiResult, true);
        $response['code'] = $apiHttpCode;

        $connect->error();
        
        return ['code' => $response['code'], 'body' => $response['response']];
    }
503541
public function fromArray(array $options)
    {
        if (isset($options['Allow'])) {
            Validate::isArray($options['Allow'], 'options[Allow]');
            foreach ($options['Allow'] as $allow) {
                $this->_allow[] = IPRange::createFromOptions($allow);
            }
        }
    }
430776
final public function curlSetOptArray(array $options = array())
	{
		$this->curlFilterOpts($options);
		curl_setopt_array($this->curl_handle, $options);
		return $this;
	}
1100844
public function getData(array $options)
    {
        $clientIDs = preg_split("/[[:space:]]+/isu", $this->options['clientId']);

        foreach ($clientIDs as $clientID) {
            if (! $clientID) {
                continue;
            }

            $client = new Google_Client([
                'client_id' => $clientID
            ]);

            $payload = $client->verifyIdToken($this->idToken);
            if ($payload) {
                break;
            }
        }

        if (! $payload) {
            throw new Exception("idToken verification failed");
        }

        $photoUrl = $payload['picture'];
        if ($photoUrl) {
            $photoUrl = $this->setSizeParam($photoUrl, 640);
        }

        return new Result([
            'externalId' => $payload['sub'],
            'name'       => $payload['name'],
            'profileUrl' => '',
            'photoUrl'   => $photoUrl,
            'location'   => '',
            'language'   => $payload['locale'],
            'email'      => $payload['email']
        ]);
    }
733382
protected function process(array $options)
    {
        $event = $this->startProfiling($this->getName(), 'get');

        $response = $this->getClient()->get($this->url, ['query' => $options]);
        $json = json_decode($response->getBody()->getContents(), true);

        $result = isset($json['data']['languages']) ? $json['data']['languages'] : [];

        $this->stopProfiling($event, $this->getName(), $result);

        return $result;
    }
823981
final public function execute($options = null)
    {
        return $this
            ->getHttpClient()
            ->request(
                $this->method(), 
                $this->uri(), 
                $options ?: $this->options()
            );
    }
669536
public function execute($options = array())
    {
        $message = $options['message'];
        $receivers = $message->getReceivers();

        $options['provide_link'] = true;
        foreach ($receivers as $receiver) {
            if ($number = $receiver->getMobilePhoneNumber())
                $this->sendSms($message, $number, $options);
            if ($email = $this->extractEmailFromReceiver($receiver))
                $this->sendMail($message, $email, $options);
            $this->sendNotification($receiver, $message->getBody(), array('message_type' => 'PM'));
        }
    }
1156013
protected function _curl($url,$options) {
		$curl=curl_init($url);
		curl_setopt($curl,CURLOPT_FOLLOWLOCATION,
			$options['follow_location']);
		curl_setopt($curl,CURLOPT_MAXREDIRS,
			$options['max_redirects']);
		curl_setopt($curl,CURLOPT_CUSTOMREQUEST,$options['method']);
		if (isset($options['header']))
			curl_setopt($curl,CURLOPT_HTTPHEADER,$options['header']);
		if (isset($options['content']))
			curl_setopt($curl,CURLOPT_POSTFIELDS,$options['content']);
		curl_setopt($curl,CURLOPT_ENCODING,'gzip,deflate');
		$timeout=isset($options['timeout'])?
			$options['timeout']:
			ini_get('default_socket_timeout');
		curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,$timeout);
		curl_setopt($curl,CURLOPT_TIMEOUT,$timeout);
		$headers=array();
		curl_setopt($curl,CURLOPT_HEADERFUNCTION,
			// Callback for response headers
			function($curl,$line) use(&$headers) {
				if ($trim=trim($line))
					$headers[]=$trim;
				return strlen($line);
			}
		);
		curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
		ob_start();
		curl_exec($curl);
		curl_close($curl);
		$body=ob_get_clean();
		return array(
			'body'=>$body,
			'headers'=>$headers,
			'engine'=>'cURL',
			'cached'=>FALSE
		);
	}
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;
	}
451259
private function executeRequest($parameters = array()) {

        $curl_options = array(
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => 2,
            CURLOPT_CUSTOMREQUEST  => 'POST',
            CURLOPT_CONNECTTIMEOUT => $this->curlTimeout,
            CURLOPT_TIMEOUT        => $this->curlConnectTimeout,
            CURLOPT_POST           => true,
            CURLOPT_POSTFIELDS     => $parameters,
            CURLOPT_URL            => $this->apiUrl[$this->mode]
        );

        $ch = curl_init();
        curl_setopt_array($ch, $curl_options);

        $result = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if ($curl_error = curl_error($ch)) {
            throw new CFException($curl_error, CFException::CURL_ERROR);
        }

        $json_decode = json_decode($result, true);
        curl_close($ch);

        // Handling API errors
        if ((is_array($json_decode) && !empty($json_decode['err_code'])) || $json_decode['result'] == 'error') {
            throw new BadResponseException($json_decode['msg']);
        }
        if ($http_code !== 200) {
            throw new \HttpResponseException('HTTP Non-200 response', $http_code);
        }
        if (json_last_error() !== \JSON_ERROR_NONE) {
            throw new DecodeException('JSON decoding error', json_last_error());
        }

        return $json_decode;
    }