Example #1
0
 /**
  * Performs generic request.
  *
  * @param array $curlOptArray the options array for CURL
  * @param \iveeCrest\Response $response object
  * @param bool $cache whether the response should be cached. If using another caching layer, it is advisable to
  * disabled it here to prevent redundant caching.
  *
  * @return void
  * @throws \iveeCrest\Exceptions\CrestException on http return codes other than 200 and 302
  */
 protected function doRequest(array $curlOptArray, Response $response, $cache = true)
 {
     //set the curl options
     curl_setopt_array($this->ch, $curlOptArray);
     //execute request
     $resBody = curl_exec($this->ch);
     $info = curl_getinfo($this->ch);
     $err = curl_errno($this->ch);
     $errmsg = curl_error($this->ch);
     if ($err != 0) {
         $crestExceptionClass = Config::getIveeClassName('CrestException');
         throw new $crestExceptionClass($errmsg, $err);
     }
     if (!in_array($info['http_code'], array(200, 302))) {
         $crestExceptionClass = Config::getIveeClassName('CrestException');
         throw new $crestExceptionClass('HTTP response not OK: ' . (int) $info['http_code'] . '. Response body: ' . $resBody, $info['http_code']);
     }
     //set data to response and cache it
     $response->setContentAndInfo($resBody, $info);
     if ($cache) {
         $this->cache->setItem($response);
     }
 }