getBody() public method

public getBody ( ) : string
return string
Exemplo n.º 1
0
 /**
  * Outputs a response depending on the set cURL option.
  *
  * The response body can be written to a file, returned, echoed or
  * passed to a custom function.
  *
  * The response header might be passed to a custom function.
  *
  * @param  Response $response    Response which contains the response body.
  * @param  array    $curlOptions cURL options which are not stored within the Response.
  * @param  resource $ch          cURL handle to add headers if needed.
  *
  * @return null|string
  */
 public static function handleOutput(Response $response, array $curlOptions, $ch)
 {
     if (isset($curlOptions[CURLOPT_HEADERFUNCTION])) {
         $headers = $response->getRawHeaders();
         call_user_func($curlOptions[CURLOPT_HEADERFUNCTION], $ch, $headers);
     }
     $body = (string) $response->getBody(true);
     if (!empty($curlOptions[CURLOPT_HEADER])) {
         $body = $response->getRawHeaders() . $body;
     }
     if (isset($curlOptions[CURLOPT_WRITEFUNCTION])) {
         call_user_func($curlOptions[CURLOPT_WRITEFUNCTION], $ch, $body);
     } elseif (isset($curlOptions[CURLOPT_RETURNTRANSFER]) && $curlOptions[CURLOPT_RETURNTRANSFER] == true) {
         return $body;
     } elseif (isset($curlOptions[CURLOPT_FILE])) {
         $fp = $curlOptions[CURLOPT_FILE];
         fwrite($fp, $body);
         fflush($fp);
     } else {
         echo $body;
     }
 }
Exemplo n.º 2
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;
 }