2013-06-19 09:13:51 +00:00
|
|
|
<?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
|
2015-01-19 20:45:05 +00:00
|
|
|
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
2013-06-19 09:13:51 +00:00
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once 'Zend/Service/Rackspace/Files.php';
|
|
|
|
|
|
|
|
class Zend_Service_Rackspace_Files_Container
|
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
const ERROR_PARAM_FILE_CONSTRUCT = 'The Zend_Service_Rackspace_Files passed in construction is not valid';
|
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
const ERROR_PARAM_ARRAY_CONSTRUCT = 'The array passed in construction is not valid';
|
2014-05-01 17:52:31 +00:00
|
|
|
|
|
|
|
const ERROR_PARAM_NO_NAME = 'The container name is empty';
|
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $name;
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Construct
|
|
|
|
*
|
|
|
|
* @param Zend_Service_Rackspace_Files $service
|
2014-05-01 17:52:31 +00:00
|
|
|
* @param $data
|
|
|
|
*
|
|
|
|
* @throws Zend_Service_Rackspace_Files_Exception
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function __construct($service, $data)
|
|
|
|
{
|
|
|
|
if (!($service instanceof Zend_Service_Rackspace_Files)) {
|
|
|
|
require_once 'Zend/Service/Rackspace/Files/Exception.php';
|
2014-05-01 17:52:31 +00:00
|
|
|
throw new Zend_Service_Rackspace_Files_Exception(
|
|
|
|
self::ERROR_PARAM_FILE_CONSTRUCT
|
|
|
|
);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
|
|
|
if (!is_array($data)) {
|
|
|
|
require_once 'Zend/Service/Rackspace/Files/Exception.php';
|
2014-05-01 17:52:31 +00:00
|
|
|
throw new Zend_Service_Rackspace_Files_Exception(
|
|
|
|
self::ERROR_PARAM_ARRAY_CONSTRUCT
|
|
|
|
);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
|
|
|
if (!array_key_exists('name', $data)) {
|
|
|
|
require_once 'Zend/Service/Rackspace/Files/Exception.php';
|
2014-05-01 17:52:31 +00:00
|
|
|
throw new Zend_Service_Rackspace_Files_Exception(
|
|
|
|
self::ERROR_PARAM_NO_NAME
|
|
|
|
);
|
|
|
|
}
|
2013-06-19 09:13:51 +00:00
|
|
|
$this->service = $service;
|
2014-05-01 17:52:31 +00:00
|
|
|
$this->name = $data['name'];
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the name of the container
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the size in bytes of the container
|
|
|
|
*
|
2014-05-01 17:52:31 +00:00
|
|
|
* @return integer|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function getSize()
|
|
|
|
{
|
|
|
|
$data = $this->getInfo();
|
|
|
|
if (isset($data['bytes'])) {
|
|
|
|
return $data['bytes'];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the total count of objects in the container
|
|
|
|
*
|
2014-05-01 17:52:31 +00:00
|
|
|
* @return integer|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function getObjectCount()
|
|
|
|
{
|
|
|
|
$data = $this->getInfo();
|
|
|
|
if (isset($data['count'])) {
|
|
|
|
return $data['count'];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Return true if the container is CDN enabled
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function isCdnEnabled()
|
|
|
|
{
|
|
|
|
$data = $this->getCdnInfo();
|
|
|
|
if (isset($data['cdn_enabled'])) {
|
|
|
|
return $data['cdn_enabled'];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the TTL of the CDN
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return integer|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function getCdnTtl()
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
|
|
|
$data = $this->getCdnInfo();
|
2014-05-01 17:52:31 +00:00
|
|
|
if (isset($data['ttl'])) {
|
2013-06-19 09:13:51 +00:00
|
|
|
return $data['ttl'];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Return true if the log retention is enabled for the CDN
|
|
|
|
*
|
2014-05-01 17:52:31 +00:00
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function isCdnLogEnabled()
|
|
|
|
{
|
|
|
|
$data = $this->getCdnInfo();
|
2014-05-01 17:52:31 +00:00
|
|
|
if (isset($data['log_retention'])) {
|
2013-06-19 09:13:51 +00:00
|
|
|
return $data['log_retention'];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the CDN URI
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return string|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function getCdnUri()
|
|
|
|
{
|
|
|
|
$data = $this->getCdnInfo();
|
2014-05-01 17:52:31 +00:00
|
|
|
if (isset($data['cdn_uri'])) {
|
2013-06-19 09:13:51 +00:00
|
|
|
return $data['cdn_uri'];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the CDN URI SSL
|
|
|
|
*
|
2014-05-01 17:52:31 +00:00
|
|
|
* @return string|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function getCdnUriSsl()
|
|
|
|
{
|
|
|
|
$data = $this->getCdnInfo();
|
2014-05-01 17:52:31 +00:00
|
|
|
if (isset($data['cdn_uri_ssl'])) {
|
2013-06-19 09:13:51 +00:00
|
|
|
return $data['cdn_uri_ssl'];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the metadata of the container
|
|
|
|
*
|
|
|
|
* If $key is empty return the array of metadata
|
|
|
|
*
|
|
|
|
* @param string $key
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return array|string|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function getMetadata($key = null)
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
|
|
|
$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];
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the information of the container (total of objects, total size)
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return array|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function getInfo()
|
|
|
|
{
|
|
|
|
$result = $this->service->getMetadataContainer($this->getName());
|
|
|
|
if (!empty($result) && is_array($result)) {
|
2014-05-01 17:52:31 +00:00
|
|
|
return $result;
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get all the object of the container
|
|
|
|
*
|
|
|
|
* @return Zend_Service_Rackspace_Files_ObjectList
|
|
|
|
*/
|
|
|
|
public function getObjects()
|
|
|
|
{
|
|
|
|
return $this->service->getObjects($this->getName());
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get an object of the container
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
2013-06-19 09:13:51 +00:00
|
|
|
* @param string $name
|
2014-05-01 17:52:31 +00:00
|
|
|
* @param array $headers
|
|
|
|
*
|
|
|
|
* @return Zend_Service_Rackspace_Files_Object|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function getObject($name, $headers = array())
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
|
|
|
return $this->service->getObject($this->getName(), $name, $headers);
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Add an object in the container
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $file the content of the object
|
2014-05-01 17:52:31 +00:00
|
|
|
* @param array $metadata
|
|
|
|
*
|
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function addObject($name, $file, $metadata = array())
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
return $this->service->storeObject(
|
|
|
|
$this->getName(), $name, $file, $metadata
|
|
|
|
);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Delete an object in the container
|
|
|
|
*
|
|
|
|
* @param string $obj
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
|
|
|
public function deleteObject($obj)
|
|
|
|
{
|
|
|
|
return $this->service->deleteObject($this->getName(), $obj);
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Copy an object to another container
|
|
|
|
*
|
|
|
|
* @param string $obj_source
|
|
|
|
* @param string $container_dest
|
|
|
|
* @param string $obj_dest
|
2014-05-01 17:52:31 +00:00
|
|
|
* @param array $metadata
|
2013-06-19 09:13:51 +00:00
|
|
|
* @param string $content_type
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function copyObject(
|
|
|
|
$obj_source, $container_dest, $obj_dest, $metadata = array(),
|
|
|
|
$content_type = null
|
|
|
|
)
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
return $this->service->copyObject(
|
|
|
|
$this->getName(),
|
|
|
|
$obj_source,
|
|
|
|
$container_dest,
|
|
|
|
$obj_dest,
|
|
|
|
$metadata,
|
|
|
|
$content_type
|
|
|
|
);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the metadata of an object in the container
|
|
|
|
*
|
|
|
|
* @param string $object
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
2013-06-19 09:13:51 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getMetadataObject($object)
|
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
return $this->service->getMetadataObject($this->getName(), $object);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Set the metadata of an object in the container
|
|
|
|
*
|
|
|
|
* @param string $object
|
2014-05-01 17:52:31 +00:00
|
|
|
* @param array $metadata
|
|
|
|
*
|
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function setMetadataObject($object, $metadata = array())
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
return $this->service->setMetadataObject(
|
|
|
|
$this->getName(), $object, $metadata
|
|
|
|
);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Enable the CDN for the container
|
|
|
|
*
|
|
|
|
* @param integer $ttl
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return array|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function enableCdn($ttl = Zend_Service_Rackspace_Files::CDN_TTL_MIN)
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
return $this->service->enableCdnContainer($this->getName(), $ttl);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Disable the CDN for the container
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function disableCdn()
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
$result =
|
|
|
|
$this->service->updateCdnContainer($this->getName(), null, false);
|
|
|
|
|
|
|
|
return ($result !== false);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Change the TTL for the CDN container
|
|
|
|
*
|
|
|
|
* @param integer $ttl
|
2014-05-01 17:52:31 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function changeTtlCdn($ttl)
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
$result = $this->service->updateCdnContainer($this->getName(), $ttl);
|
|
|
|
|
|
|
|
return ($result !== false);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Enable the log retention for the CDN
|
|
|
|
*
|
2014-05-01 17:52:31 +00:00
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function enableLogCdn()
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
$result = $this->service->updateCdnContainer(
|
|
|
|
$this->getName(), null, null, true
|
|
|
|
);
|
|
|
|
|
|
|
|
return ($result !== false);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Disable the log retention for the CDN
|
|
|
|
*
|
2014-05-01 17:52:31 +00:00
|
|
|
* @return bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function disableLogCdn()
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
2014-05-01 17:52:31 +00:00
|
|
|
$result = $this->service->updateCdnContainer(
|
|
|
|
$this->getName(), null, null, false
|
|
|
|
);
|
|
|
|
|
|
|
|
return ($result !== false);
|
2013-06-19 09:13:51 +00:00
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
|
2013-06-19 09:13:51 +00:00
|
|
|
/**
|
|
|
|
* Get the CDN information
|
|
|
|
*
|
2014-05-01 17:52:31 +00:00
|
|
|
* @return array|bool
|
2013-06-19 09:13:51 +00:00
|
|
|
*/
|
2014-05-01 17:52:31 +00:00
|
|
|
public function getCdnInfo()
|
2013-06-19 09:13:51 +00:00
|
|
|
{
|
|
|
|
return $this->service->getInfoCdnContainer($this->getName());
|
|
|
|
}
|
2014-05-01 17:52:31 +00:00
|
|
|
}
|