/** * Execute request * * @param string $path * @param array $options * @param bool $throwExceptions * * @return Response * * @codeCoverageIgnore */ public function execute($path, array $options = array(), $throwExceptions = false) { $this->path = $path; $this->options = $options; $session = curl_init($this->url . '/api/' . $path); // Merge options with preserving keys $curlOptions = static::$defaults; $curlOptions[CURLOPT_USERPWD] = $this->key . ':'; foreach ($options as $key => $val) { $curlOptions[$key] = $val; } curl_setopt_array($session, $curlOptions); $response = $this->executeCURLRetries($session); $code = curl_getinfo($session, CURLINFO_HTTP_CODE); $error = curl_error($session); curl_close($session); if ($code === 0) { throw new Exception\RuntimeException('CURL Error: ' . $error); } $index = strpos($response, "\r\n\r\n"); $headers = Response::parseHeaders($index !== false ? substr($response, 0, $index) : $response); $content = $index !== false ? substr($response, $index + 4) : null; if (null === $content && $curlOptions[CURLOPT_CUSTOMREQUEST] !== 'HEAD') { throw new Exception\RuntimeException('Bad HTTP response'); } if (array_key_exists('PSWS-Version', $headers)) { Version::validatePSVersion($headers['PSWS-Version']); } $response = new Response($content, $code, $headers); if ($throwExceptions && !$response->isValid()) { $this->throwExceptions($response); } return $response; }