File indexing completed on 2025-01-26 05:25:27
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service_Rackspace 0017 * @subpackage Files 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 */ 0021 0022 // require_once 'Zend/Service/Rackspace/Files.php'; 0023 0024 class Zend_Service_Rackspace_Files_Object 0025 { 0026 /** 0027 * The service that has created the object 0028 * 0029 * @var Zend_Service_Rackspace_Files 0030 */ 0031 protected $service; 0032 0033 /** 0034 * Name of the object 0035 * 0036 * @var string 0037 */ 0038 protected $name; 0039 0040 /** 0041 * MD5 value of the object's content 0042 * 0043 * @var string 0044 */ 0045 protected $hash; 0046 0047 /** 0048 * Size in bytes of the object's content 0049 * 0050 * @var integer 0051 */ 0052 protected $size; 0053 0054 /** 0055 * Content type of the object's content 0056 * 0057 * @var string 0058 */ 0059 protected $contentType; 0060 0061 /** 0062 * Date of the last modified of the object 0063 * 0064 * @var string 0065 */ 0066 protected $lastModified; 0067 0068 /** 0069 * Object content 0070 * 0071 * @var string 0072 */ 0073 protected $content; 0074 0075 /** 0076 * Name of the container where the object is stored 0077 * 0078 * @var string 0079 */ 0080 protected $container; 0081 0082 /** 0083 * Constructor 0084 * 0085 * You must pass the Zend_Service_Rackspace_Files object of the caller and an associative 0086 * array with the keys "name", "container", "hash", "bytes", "content_type", 0087 * "last_modified", "file" where: 0088 * name= name of the object 0089 * container= name of the container where the object is stored 0090 * hash= the MD5 of the object's content 0091 * bytes= size in bytes of the object's content 0092 * content_type= content type of the object's content 0093 * last_modified= date of the last modified of the object 0094 * content= content of the object 0095 * 0096 * @param Zend_Service_Rackspace_Files $service 0097 * @param array $data 0098 * @throws Zend_Service_Rackspace_Files_Exception 0099 */ 0100 public function __construct($service, $data) 0101 { 0102 if (!($service instanceof Zend_Service_Rackspace_Files) || !is_array($data)) { 0103 // require_once 'Zend/Service/Rackspace/Files/Exception.php'; 0104 throw new Zend_Service_Rackspace_Files_Exception( 0105 'You must pass a RackspaceFiles and an array' 0106 ); 0107 } 0108 if (!array_key_exists('container', $data)) { 0109 // require_once 'Zend/Service/Rackspace/Files/Exception.php'; 0110 throw new Zend_Service_Rackspace_Files_Exception( 0111 'You must pass the container of the object in the array (container)' 0112 ); 0113 } 0114 if (array_key_exists('name', $data)) { 0115 if (!array_key_exists('hash', $data)) { 0116 // require_once 'Zend/Service/Rackspace/Files/Exception.php'; 0117 throw new Zend_Service_Rackspace_Files_Exception( 0118 'You must pass the hash of the object in the array (hash)' 0119 ); 0120 } 0121 if (!array_key_exists('bytes', $data)) { 0122 // require_once 'Zend/Service/Rackspace/Files/Exception.php'; 0123 throw new Zend_Service_Rackspace_Files_Exception( 0124 'You must pass the byte size of the object in the array (bytes)' 0125 ); 0126 } 0127 if (!array_key_exists('content_type', $data)) { 0128 // require_once 'Zend/Service/Rackspace/Files/Exception.php'; 0129 throw new Zend_Service_Rackspace_Files_Exception( 0130 'You must pass the content type of the object in the array (content_type)' 0131 ); 0132 } 0133 if (!array_key_exists('last_modified', $data)) { 0134 // require_once 'Zend/Service/Rackspace/Files/Exception.php'; 0135 throw new Zend_Service_Rackspace_Files_Exception( 0136 'You must pass the last modified data of the object in the array (last_modified)' 0137 ); 0138 } 0139 0140 $this->name = $data['name']; 0141 $this->hash = $data['hash']; 0142 $this->size = $data['bytes']; 0143 $this->contentType = $data['content_type']; 0144 $this->lastModified = $data['last_modified']; 0145 0146 if (!empty($data['content'])) { 0147 $this->content = $data['content']; 0148 } 0149 } elseif (array_key_exists('subdir', $data)) { 0150 $this->name = $data['subdir']; 0151 } else { 0152 // require_once 'Zend/Service/Rackspace/Files/Exception.php'; 0153 throw new Zend_Service_Rackspace_Files_Exception( 0154 'You must pass the name of the object in the array (name)' 0155 ); 0156 } 0157 0158 $this->container = $data['container']; 0159 $this->service = $service; 0160 } 0161 0162 /** 0163 * Get name 0164 * 0165 * @return string 0166 */ 0167 public function getName() 0168 { 0169 return $this->name; 0170 } 0171 0172 /** 0173 * Get the name of the container 0174 * 0175 * @return string 0176 */ 0177 public function getContainer() 0178 { 0179 return $this->container; 0180 } 0181 0182 /** 0183 * Get the MD5 of the object's content 0184 * 0185 * @return string|boolean 0186 */ 0187 public function getHash() 0188 { 0189 return $this->hash; 0190 } 0191 0192 /** 0193 * Get the size (in bytes) of the object's content 0194 * 0195 * @return integer|boolean 0196 */ 0197 public function getSize() 0198 { 0199 return $this->size; 0200 } 0201 0202 /** 0203 * Get the content type of the object's content 0204 * 0205 * @return string 0206 */ 0207 public function getContentType() 0208 { 0209 return $this->contentType; 0210 } 0211 0212 /** 0213 * Get the data of the last modified of the object 0214 * 0215 * @return string 0216 */ 0217 public function getLastModified() 0218 { 0219 return $this->lastModified; 0220 } 0221 0222 /** 0223 * Get the content of the object 0224 * 0225 * @return string 0226 */ 0227 public function getContent() 0228 { 0229 return $this->content; 0230 } 0231 0232 /** 0233 * Get the metadata of the object 0234 * If you don't pass the $key it returns the entire array of metadata value 0235 * 0236 * @param string $key 0237 * @return string|array|boolean 0238 */ 0239 public function getMetadata($key=null) 0240 { 0241 $result= $this->service->getMetadataObject($this->container,$this->name); 0242 if (!empty($result)) { 0243 if (empty($key)) { 0244 return $result['metadata']; 0245 } 0246 if (isset($result['metadata'][$key])) { 0247 return $result['metadata'][$key]; 0248 } 0249 } 0250 return false; 0251 } 0252 0253 /** 0254 * Set the metadata value 0255 * The old metadata values are replaced with the new one 0256 * 0257 * @param array $metadata 0258 * @return boolean 0259 */ 0260 public function setMetadata($metadata) 0261 { 0262 return $this->service->setMetadataObject($this->container,$this->name,$metadata); 0263 } 0264 0265 /** 0266 * Copy the object to another container 0267 * You can add metadata information to the destination object, change the 0268 * content_type and the name of the object 0269 * 0270 * @param string $container_dest 0271 * @param string $name_dest 0272 * @param array $metadata 0273 * @param string $content_type 0274 * @return boolean 0275 */ 0276 public function copyTo($container_dest,$name_dest,$metadata=array(),$content_type=null) 0277 { 0278 return $this->service->copyObject($this->container,$this->name,$container_dest,$name_dest,$metadata,$content_type); 0279 } 0280 0281 /** 0282 * Get the CDN URL of the object 0283 * 0284 * @return string 0285 */ 0286 public function getCdnUrl() 0287 { 0288 $result= $this->service->getInfoCdnContainer($this->container); 0289 if ($result!==false) { 0290 if ($result['cdn_enabled']) { 0291 return $result['cdn_uri'].'/'.$this->name; 0292 } 0293 } 0294 return false; 0295 } 0296 0297 /** 0298 * Get the CDN SSL URL of the object 0299 * 0300 * @return string 0301 */ 0302 public function getCdnUrlSsl() 0303 { 0304 $result= $this->service->getInfoCdnContainer($this->container); 0305 if ($result!==false) { 0306 if ($result['cdn_enabled']) { 0307 return $result['cdn_uri_ssl'].'/'.$this->name; 0308 } 0309 } 0310 return false; 0311 } 0312 }