/** * Performs generic request. * * @param array $curlOptArray the options array for CURL * @param \iveeCrest\Response $response object * * @return void * @throws \iveeCrest\Exceptions\CrestException on http return codes other than 200 and 302 */ protected function doRequest(array $curlOptArray, Response $response) { //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->setInfo($info); $response->setContent($resBody); $this->cache->setItem($response); }
public function testGetCurlInfoFromArray() { $curlOptions = array('option' => 'value'); $response = new Response(200); $response->setInfo($curlOptions); $restoredResponse = Response::fromArray($response->toArray()); $this->assertEquals($curlOptions, $restoredResponse->getInfo()); }