예제 #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.
  *
  * @return \OpenStack\ObjectStore\v1\Resource\RemoteObject A new RemoteObject.
  */
 public static function newFromHeaders($name, $headers, $token, $url, ClientInterface $client = 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;
     if (is_null($client)) {
         $client = GuzzleAdapter::create();
     }
     $object->setClient($client);
     return $object;
 }