Ejemplo n.º 1
0
 /**
  * Fetch an object, but delay fetching its contents.
  *
  * This retrieves all of the information about an object except for
  * its contents. Size, hash, metadata, and modification date
  * information are all retrieved and wrapped.
  *
  * The data comes back as a RemoteObject, which can be used to
  * transparently fetch the object's content, too.
  *
  * Why Use This?
  *
  * The regular object() call will fetch an entire object, including
  * its content. This may not be desireable for cases where the object
  * is large.
  *
  * This method can featch the relevant metadata, but delay fetching
  * the content until it is actually needed.
  *
  * Since RemoteObject extends Object, all of the calls that can be
  * made to an Object can also be made to a RemoteObject. Be aware,
  * though, that calling RemoteObject::content() will initiate another
  * network operation.
  *
  * @param string $name
  *   The name of the object to fetch.
  * @retval HPCloud::Storage::ObjectStorage::RemoteObject
  * @return \HPCloud\Storage\ObjectStorage\RemoteObject
  *   A remote object ready for use.
  */
 public function proxyObject($name)
 {
     $url = self::objectUrl($this->url, $name);
     $cdn = self::objectUrl($this->cdnUrl, $name);
     $cdnSsl = self::objectUrl($this->cdnSslUrl, $name);
     $headers = array('X-Auth-Token' => $this->token);
     $client = \HPCloud\Transport::instance();
     if (empty($this->cdnUrl)) {
         $response = $client->doRequest($url, 'HEAD', $headers);
     } else {
         $response = $client->doRequest($cdnSsl, 'HEAD', $headers);
     }
     if ($response->status() != 200) {
         throw new \HPCloud\Exception('An unknown error occurred while saving: ' . $response->status());
     }
     $headers = $response->headers();
     $obj = RemoteObject::newFromHeaders($name, $headers, $this->token, $url);
     if (!empty($this->cdnUrl)) {
         $obj->useCDN($cdn, $cdnSsl);
     }
     return $obj;
 }