Пример #1
0
 /**
  * Extract information from HTTP headers.
  *
  * This is used internally to set object properties from headers.
  *
  * @retval HPCloud::Storage::ObjectStorage::RemoteObject
  * @return \HPCloud\Storage\ObjectStorage\RemoteObject
  *   $this for the current object so it can be used in chaining methods.
  */
 protected function extractFromHeaders($response)
 {
     $this->setContentType($response->header('Content-Type', $this->contentType()));
     $this->lastModified = strtotime($response->header('Last-Modified', 0));
     $this->etag = $response->header('Etag', $this->etag);
     $this->contentLength = (int) $response->header('Content-Length', 0);
     $this->setDisposition($response->header('Content-Disposition', NULL));
     $this->setEncoding($response->header('Content-Encoding', NULL));
     // Reset the metadata, too:
     $this->setMetadata(Container::extractHeaderAttributes($response->headers()));
     return $this;
 }
Пример #2
0
 /**
  * Get missing fields.
  *
  * Not all containers come fully instantiated. This method is sometimes
  * called to "fill in" missing fields.
  *
  * @retval HPCloud::Storage::ObjectStorage::Comtainer
  * @return \HPCloud\Storage\ObjectStorage\Container
  */
 protected function loadExtraData()
 {
     // If URL and token are empty, we are dealing with
     // a local item that has not been saved, and was not
     // created with Container::createContainer(). We treat
     // this as an error condition.
     if (empty($this->url) || empty($this->token)) {
         throw new \HPCloud\Exception('Remote data cannot be fetched. Tokena and endpoint URL are required.');
     }
     // Do a GET on $url to fetch headers.
     $client = \HPCloud\Transport::instance();
     $headers = array('X-Auth-Token' => $this->token);
     $response = $client->doRequest($this->url, 'GET', $headers);
     // Get ACL.
     $this->acl = ACL::newFromHeaders($response->headers());
     // Update size and count.
     $this->bytes = $response->header('X-Container-Bytes-Used', 0);
     $this->count = $response->header('X-Container-Object-Count', 0);
     // Get metadata.
     $prefix = Container::CONTAINER_METADATA_HEADER_PREFIX;
     $this->setMetadata(Container::extractHeaderAttributes($response->headers(), $prefix));
     return $this;
 }