/** * Prepares parameters that are required for sending and performs sending to Telegram's * servers via CURL and returns the result from CURL. * * @param AbstractMethod $methodInstance * * @return mixed */ protected function sendRequest(AbstractMethod $methodInstance) { if (!$this->ch) { $this->ch = curl_init(); } $name = $methodInstance->getName(); $curlOptions = [CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => Config::REQUEST_TIMEOUT]; // Default method is always POST if ($this->config->getMethod() !== self::METHOD_GET) { $curlOptions[CURLOPT_POST] = 1; if ($methodInstance->hasAttachedData()) { $curlOptions[CURLOPT_HTTPHEADER] = [static::CONTENT_TYPE_MULTIPART]; $curlOptions[CURLOPT_SAFE_UPLOAD] = 1; } $curlOptions[CURLOPT_POSTFIELDS] = $methodInstance->getPropertiesArray(); $curlOptions[CURLOPT_URL] = $this->buildUrl($name); } else { $curlOptions[CURLOPT_URL] = $this->buildUrl($name, $methodInstance->getPropertiesAsString()); } curl_setopt_array($this->ch, $curlOptions); return curl_exec($this->ch); }