Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * @param  string                                     $url
  * @param  string                                     $method
  * @param  array                                      $querydata
  * @param  array                                      $headers
  * @param  array                                      $options
  * @return array
  * @throws \OpenStackStorage\Exceptions\ResponseError
  * @throws \OpenStackStorage\Exceptions\Error
  */
 public function sendRequest($url, $method = 'GET', $querydata = null, $headers = null, $options = null)
 {
     if (null === $headers) {
         $headers = array();
     } elseif (!is_array($headers)) {
         $headers = (array) $headers;
     }
     if (null === $options) {
         $options = array();
     } elseif (!is_array($options)) {
         $options = (array) $options;
     }
     if (!array_key_exists('timeout', $options)) {
         $options['timeout'] = $this->timeout;
     }
     if ($method == self::PUT && !array_key_exists('Content-Length', $headers)) {
         if (empty($querydata)) {
             $headers['Content-Length'] = 0;
         } else {
             $headers['Content-Length'] = is_string($querydata) ? strlen($querydata) : strlen(http_build_query($querydata));
         }
     }
     $response = parent::sendRequest($url, $method, $querydata, $headers, $options);
     if (array_key_exists('error_msg', $response) && null !== $response['error_msg']) {
         throw new Exceptions\Error(substr($response['error_msg'], 0, strpos($response['error_msg'], ';')));
     }
     if ($response['status'] >= 400) {
         throw new Exceptions\ResponseError($response['status']);
     }
     $response['headers'] = new Client\Headers($response['headers']);
     return $response;
 }