示例#1
0
 /**
  * Returns a cURL option from a Response.
  *
  * @param  Response $response Response to get cURL option from.
  * @param  integer $option cURL option to get.
  *
  * @throws \BadMethodCallException
  * @return mixed Value of the cURL option.
  */
 public static function getCurlOptionFromResponse(Response $response, $option = 0)
 {
     switch ($option) {
         case 0:
             // 0 == array of all curl options
             $info = array();
             foreach (self::$curlInfoList as $option => $key) {
                 $info[$key] = $response->getInfo($option);
             }
             break;
         case CURLINFO_HTTP_CODE:
             $info = $response->getStatusCode();
             break;
         case CURLINFO_SIZE_DOWNLOAD:
             $info = $response->getHeader('Content-Length');
             break;
         default:
             $info = $response->getInfo($option);
             break;
     }
     if (!is_null($info)) {
         return $info;
     }
     $constants = get_defined_constants(true);
     $constantNames = array_flip($constants['curl']);
     throw new \BadMethodCallException("Not implemented: {$constantNames[$option]} ({$option}) ");
 }
示例#2
0
 /**
  * Records a request and response pair.
  *
  * @param Request  $request  Request to record.
  * @param Response $response Response to record.
  *
  * @return void
  */
 public function record(Request $request, Response $response)
 {
     if ($this->hasResponse($request)) {
         return;
     }
     $recording = array('request' => $request->toArray(), 'response' => $response->toArray());
     $this->storage->storeRecording($recording);
 }
示例#3
0
 /**
  * Seeks to specific location in a stream.
  *
  * @param  integer $offset The stream offset to seek to.
  * @param  integer $whence Possible values:
  *                         SEEK_SET - Set position equal to offset bytes.
  *                         SEEK_CUR - Set position to current location plus offset.
  *                         SEEK_END - Set position to end-of-file plus offset.
  * @return boolean Return TRUE if the position was updated, FALSE otherwise.
  */
 public function stream_seek($offset, $whence)
 {
     switch ($whence) {
         case SEEK_SET:
             if ($offset < strlen($this->response->getBody()) && $offset >= 0) {
                 $this->position = $offset;
                 return true;
             }
             break;
         case SEEK_CUR:
             if ($offset >= 0) {
                 $this->position += $offset;
                 return true;
             }
             break;
         case SEEK_END:
             if (strlen($this->response->getBody()) + $offset >= 0) {
                 $this->position = strlen($this->response->getBody()) + $offset;
                 return true;
             }
     }
     return false;
 }
示例#4
0
 /**
  * Returns a HTTP status line with headers from specified response.
  *
  * @param Response $response
  * @return string HTTP status line.
  */
 public static function formatAsStatusWithHeadersString(Response $response)
 {
     $headers = self::formatHeadersForCurl($response->getHeaders());
     array_unshift($headers, self::formatAsStatusString($response));
     return join("\r\n", $headers) . "\r\n\r\n";
 }
示例#5
0
 /**
  * Returns a HTTP status line from specified response.
  *
  * @param Response $response
  * @return string HTTP status line.
  */
 public static function formatAsStatusString(Response $response)
 {
     return 'HTTP/' . $response->getHttpVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getStatusMessage();
 }