tunethemusic /library/Zend/Service/Rackspace/Files/Container.php

Language PHP Lines 329
MD5 Hash 475bcc0f76ea0adcfefc9fde514bb2a9 Estimated Cost $3,996 (why?)
Repository https://bitbucket.org/hieronim1981/tunethemusic.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?php

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Service_Rackspace
 * @subpackage Files
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

require_once 'Zend/Service/Rackspace/Files.php';

class Zend_Service_Rackspace_Files_Container
{
    const ERROR_PARAM_FILE_CONSTRUCT  = 'The Zend_Service_Rackspace_Files passed in construction is not valid';
    const ERROR_PARAM_ARRAY_CONSTRUCT = 'The array passed in construction is not valid';
    const ERROR_PARAM_NO_NAME         = 'The container name is empty';
    /**
     * @var string
     */
    protected $name;
    /**
     * Construct
     *
     * @param Zend_Service_Rackspace_Files $service
     * @param string $name
     */
    public function __construct($service, $data)
    {
        if (!($service instanceof Zend_Service_Rackspace_Files)) {
            require_once 'Zend/Service/Rackspace/Files/Exception.php';
            throw new Zend_Service_Rackspace_Files_Exception(self::ERROR_PARAM_FILE_CONSTRUCT);
        }
        if (!is_array($data)) {
            require_once 'Zend/Service/Rackspace/Files/Exception.php';
            throw new Zend_Service_Rackspace_Files_Exception(self::ERROR_PARAM_ARRAY_CONSTRUCT);
        }
        if (!array_key_exists('name', $data)) {
            require_once 'Zend/Service/Rackspace/Files/Exception.php';
            throw new Zend_Service_Rackspace_Files_Exception(self::ERROR_PARAM_NO_NAME);
        }    
        $this->service = $service;
        $this->name = $data['name'];
    }
    /**
     * Get the name of the container
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
    /**
     * Get the size in bytes of the container
     *
     * @return integer|boolean
     */
    public function getSize()
    {
        $data = $this->getInfo();
        if (isset($data['bytes'])) {
            return $data['bytes'];
        }
        return false;
    }
    /**
     * Get the total count of objects in the container
     *
     * @return integer|boolean
     */
    public function getObjectCount()
    {
        $data = $this->getInfo();
        if (isset($data['count'])) {
            return $data['count'];
        }
        return false;
    }
    /**
     * Return true if the container is CDN enabled
     * 
     * @return boolean
     */
    public function isCdnEnabled()
    {
        $data = $this->getCdnInfo();
        if (isset($data['cdn_enabled'])) {
            return $data['cdn_enabled'];
        }
        return false;
    }
    /**
     * Get the TTL of the CDN
     * 
     * @return integer|boolean 
     */
    public function getCdnTtl() 
    {
        $data = $this->getCdnInfo();
        if (!isset($data['ttl'])) {
            return $data['ttl'];
        }
        return false;
    }
    /**
     * Return true if the log retention is enabled for the CDN
     *
     * @return boolean
     */
    public function isCdnLogEnabled()
    {
        $data = $this->getCdnInfo();
        if (!isset($data['log_retention'])) {
            return $data['log_retention'];
        }
        return false;
    }
    /**
     * Get the CDN URI
     * 
     * @return string|boolean
     */
    public function getCdnUri()
    {
        $data = $this->getCdnInfo();
        if (!isset($data['cdn_uri'])) {
            return $data['cdn_uri'];
        }
        return false;
    }
    /**
     * Get the CDN URI SSL
     *
     * @return string|boolean
     */
    public function getCdnUriSsl()
    {
        $data = $this->getCdnInfo();
        if (!isset($data['cdn_uri_ssl'])) {
            return $data['cdn_uri_ssl'];
        }
        return false;
    }
    /**
     * Get the metadata of the container
     *
     * If $key is empty return the array of metadata
     *
     * @param string $key
     * @return array|string|boolean
     */
    public function getMetadata($key=null)
    {
        $result = $this->service->getMetadataContainer($this->getName());
        if (!empty($result) && is_array($result)) {
            if (empty($key)) {
                return $result['metadata'];
            } else {
                if (isset ($result['metadata'][$key])) {
                    return $result['metadata'][$key];
                }
            }    
        }    
        return false;
    }
    /**
     * Get the information of the container (total of objects, total size)
     * 
     * @return array|boolean 
     */
    public function getInfo()
    {
        $result = $this->service->getMetadataContainer($this->getName());
        if (!empty($result) && is_array($result)) {
           return $result;
        }
        return false;
    }
    /**
     * Get all the object of the container
     *
     * @return Zend_Service_Rackspace_Files_ObjectList
     */
    public function getObjects()
    {
        return $this->service->getObjects($this->getName());
    }
    /**
     * Get an object of the container
     * 
     * @param string $name
     * @param array $headers
     * @return Zend_Service_Rackspace_Files_Object|boolean
     */
    public function getObject($name, $headers=array())
    {
        return $this->service->getObject($this->getName(), $name, $headers);
    }
    /**
     * Add an object in the container
     *
     * @param string $name
     * @param string $file the content of the object
     * @param array $metadata
     * @return boolen
     */
    public function addObject($name, $file, $metadata=array())
    {
        return $this->service->storeObject($this->getName(), $name, $file, $metadata);
    }
    /**
     * Delete an object in the container
     *
     * @param string $obj
     * @return boolean
     */
    public function deleteObject($obj)
    {
        return $this->service->deleteObject($this->getName(), $obj);
    }
    /**
     * Copy an object to another container
     *
     * @param string $obj_source
     * @param string $container_dest
     * @param string $obj_dest
     * @param array $metadata
     * @param string $content_type
     * @return boolean
     */
    public function copyObject($obj_source, $container_dest, $obj_dest, $metadata=array(), $content_type=null)
    {
        return $this->service->copyObject($this->getName(), $obj_source, $container_dest, $obj_dest, $metadata, $content_type);
    }
    /**
     * Get the metadata of an object in the container
     *
     * @param string $object
     * @return array
     */
    public function getMetadataObject($object)
    {
        return $this->service->getMetadataObject($this->getName(),$object);
    }
    /**
     * Set the metadata of an object in the container
     *
     * @param string $object
     * @param array $metadata
     * @return boolean
     */
    public function setMetadataObject($object,$metadata=array()) 
    {
        return $this->service->setMetadataObject($this->getName(),$object,$metadata);
    }
    /**
     * Enable the CDN for the container
     *
     * @param integer $ttl
     * @return array|boolean
     */
    public function enableCdn($ttl=Zend_Service_Rackspace_Files::CDN_TTL_MIN) 
    {
        return $this->service->enableCdnContainer($this->getName(),$ttl);
    }
    /**
     * Disable the CDN for the container
     * 
     * @return boolean
     */
    public function disableCdn() 
    {
        $result = $this->service->updateCdnContainer($this->getName(),null,false);
        return ($result!==false);
    }
    /**
     * Change the TTL for the CDN container
     *
     * @param integer $ttl
     * @return boolean
     */
    public function changeTtlCdn($ttl) 
    {
        $result =  $this->service->updateCdnContainer($this->getName(),$ttl);
        return ($result!==false);
    }
    /**
     * Enable the log retention for the CDN
     *
     * @return boolean
     */
    public function enableLogCdn() 
    {
        $result =  $this->service->updateCdnContainer($this->getName(),null,null,true);
        return ($result!==false);
    }
    /**
     * Disable the log retention for the CDN
     *
     * @return boolean
     */
    public function disableLogCdn() 
    {
        $result =  $this->service->updateCdnContainer($this->getName(),null,null,false);
        return ($result!==false);
    }
    /**
     * Get the CDN information
     *
     * @return array|boolean
     */
    public function getCdnInfo() 
    {
        return $this->service->getInfoCdnContainer($this->getName());
    }
}
Back to Top