Esempio n. 1
0
 /**
  * Create a new RemoteObject from HTTP headers.
  *
  * This is used to create objects from GET and HEAD requests, which
  * return all of the metadata inside of the headers.
  *
  * @param string $name
  *   The name of the object.
  * @param array $headers
  *   An associative array of HTTP headers in the exact format 
  *   documented by OpenStack's API docs.
  * @param string $token
  *   The current auth token (used for issuing subsequent requests).
  * @param string $url
  *   The URL to the object in the object storage. Used for issuing
  *   subsequent requests.
  * @param string $cdnUrl
  *   The URL to the CDN version of the object. Used for issuing
  *   subsequent requests. If this is set, this object may use
  *   CDN to make subsequent requests. It may also return the
  *   CDN URL when requested.
  * @param string $cdnSslUrl
  *   The URL to the SSL-protected CDN version of the object.
  *
  * @retval HPCloud::Storage::ObjectStorage::RemoteObject
  * @return \HPCloud\Storage\ObjectStorage\RemoteObject
  *   A new RemoteObject.
  */
 public static function newFromHeaders($name, $headers, $token, $url, $cdnUrl = NULL, $cdnSslUrl = NULL)
 {
     $object = new RemoteObject($name);
     //$object->allHeaders = $headers;
     $object->setHeaders($headers);
     //throw new \Exception(print_r($headers, TRUE));
     // Fix inconsistant header.
     if (isset($headers['ETag'])) {
         $headers['Etag'] = $headers['ETag'];
     }
     $object->setContentType($headers['Content-Type']);
     $object->contentLength = empty($headers['Content-Length']) ? 0 : (int) $headers['Content-Length'];
     $object->etag = (string) $headers['Etag'];
     // ETag is now Etag.
     $object->lastModified = strtotime($headers['Last-Modified']);
     // Set the metadata, too.
     $object->setMetadata(Container::extractHeaderAttributes($headers));
     // If content encoding and disposition exist, set them on the
     // object.
     if (!empty($headers['Content-Disposition'])) {
         $object->setDisposition($headers['Content-Disposition']);
     }
     if (!empty($headers['Content-Encoding'])) {
         $object->setEncoding($headers['Content-Encoding']);
     }
     $object->token = $token;
     $object->url = $url;
     $object->cdnUrl = $cdnUrl;
     $object->cdnSslUrl = $cdnSslUrl;
     return $object;
 }