name = $data['name']; $this->hash = $data['hash']; $this->size = $data['bytes']; $this->contentType = $data['content_type']; $this->lastModified = $data['last_modified']; if (!empty($data['content'])) { $this->content = $data['content']; } } elseif (array_key_exists('subdir', $data)) { $this->name = $data['subdir']; } else { require_once 'Zend/Service/Rackspace/Files/Exception.php'; throw new Zend_Service_Rackspace_Files_Exception( 'You must pass the name of the object in the array (name)' ); } $this->container = $data['container']; $this->service = $service; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Get the name of the container * * @return string */ public function getContainer() { return $this->container; } /** * Get the MD5 of the object's content * * @return string|boolean */ public function getHash() { return $this->hash; } /** * Get the size (in bytes) of the object's content * * @return integer|boolean */ public function getSize() { return $this->size; } /** * Get the content type of the object's content * * @return string */ public function getContentType() { return $this->contentType; } /** * Get the data of the last modified of the object * * @return string */ public function getLastModified() { return $this->lastModified; } /** * Get the content of the object * * @return string */ public function getContent() { return $this->content; } /** * Get the metadata of the object * If you don't pass the $key it returns the entire array of metadata value * * @param string $key * @return string|array|boolean */ public function getMetadata($key=null) { $result= $this->service->getMetadataObject($this->container,$this->name); if (!empty($result)) { if (empty($key)) { return $result['metadata']; } if (isset($result['metadata'][$key])) { return $result['metadata'][$key]; } } return false; } /** * Set the metadata value * The old metadata values are replaced with the new one * * @param array $metadata * @return boolean */ public function setMetadata($metadata) { return $this->service->setMetadataObject($this->container,$this->name,$metadata); } /** * Copy the object to another container * You can add metadata information to the destination object, change the * content_type and the name of the object * * @param string $container_dest * @param string $name_dest * @param array $metadata * @param string $content_type * @return boolean */ public function copyTo($container_dest,$name_dest,$metadata=array(),$content_type=null) { return $this->service->copyObject($this->container,$this->name,$container_dest,$name_dest,$metadata,$content_type); } /** * Get the CDN URL of the object * * @return string */ public function getCdnUrl() { $result= $this->service->getInfoCdnContainer($this->container); if ($result!==false) { if ($result['cdn_enabled']) { return $result['cdn_uri'].'/'.$this->name; } } return false; } /** * Get the CDN SSL URL of the object * * @return string */ public function getCdnUrlSsl() { $result= $this->service->getInfoCdnContainer($this->container); if ($result!==false) { if ($result['cdn_enabled']) { return $result['cdn_uri_ssl'].'/'.$this->name; } } return false; } }