web/lib/Zend/Service/Rackspace/Files.php
changeset 1230 68c69c656a2c
parent 808 6b6c2214f778
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Service
    16  * @package    Zend_Service
    17  * @subpackage Rackspace
    17  * @subpackage Rackspace
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  */
    20  */
    21 
    21 
    22 require_once 'Zend/Service/Rackspace/Abstract.php';
    22 require_once 'Zend/Service/Rackspace/Abstract.php';
    23 require_once 'Zend/Service/Rackspace/Files/ContainerList.php';
    23 require_once 'Zend/Service/Rackspace/Files/ContainerList.php';
    24 require_once 'Zend/Service/Rackspace/Files/ObjectList.php';
    24 require_once 'Zend/Service/Rackspace/Files/ObjectList.php';
    25 require_once 'Zend/Service/Rackspace/Files/Container.php';
    25 require_once 'Zend/Service/Rackspace/Files/Container.php';
    26 require_once 'Zend/Service/Rackspace/Files/Object.php';
    26 require_once 'Zend/Service/Rackspace/Files/Object.php';
    27 
    27 
       
    28 /**
       
    29  * Zend_Service_Rackspace_Files
       
    30  *
       
    31  * @category   Zend
       
    32  * @package    Zend_Service
       
    33  * @subpackage Rackspace
       
    34  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
       
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    36  */
    28 class Zend_Service_Rackspace_Files extends Zend_Service_Rackspace_Abstract
    37 class Zend_Service_Rackspace_Files extends Zend_Service_Rackspace_Abstract
    29 {
    38 {
    30     const ERROR_CONTAINER_NOT_EMPTY            = 'The container is not empty, I cannot delete it.';
    39     const ERROR_CONTAINER_NOT_EMPTY            = 'The container is not empty, I cannot delete it.';
    31     const ERROR_CONTAINER_NOT_FOUND            = 'The container was not found.';
    40     const ERROR_CONTAINER_NOT_FOUND            = 'The container was not found.';
    32     const ERROR_OBJECT_NOT_FOUND               = 'The object was not found.';
    41     const ERROR_OBJECT_NOT_FOUND               = 'The object was not found.';
    68     const MANIFEST_OBJECT_HEADER               = "X-Object-Manifest";
    77     const MANIFEST_OBJECT_HEADER               = "X-Object-Manifest";
    69 
    78 
    70     /**
    79     /**
    71      * Return the total count of containers
    80      * Return the total count of containers
    72      *
    81      *
    73      * @return integer
    82      * @return int
    74      */
    83      */
    75     public function getCountContainers()
    84     public function getCountContainers()
    76     {
    85     {
    77         $data= $this->getInfoAccount();
    86         $data= $this->getInfoAccount();
    78         return $data['tot_containers'];
    87         return $data['tot_containers'];
    79     }
    88     }
    80     /**
    89     /**
    81      * Return the size in bytes of all the containers
    90      * Return the size in bytes of all the containers
    82      *
    91      *
    83      * @return integer
    92      * @return int
    84      */
    93      */
    85     public function getSizeContainers()
    94     public function getSizeContainers()
    86     {
    95     {
    87         $data= $this->getInfoAccount();
    96         $data= $this->getInfoAccount();
    88         return $data['size_containers'];
    97         return $data['size_containers'];
    89     }
    98     }
    90     /**
    99     /**
    91      * Return the count of objects contained in all the containers
   100      * Return the count of objects contained in all the containers
    92      *
   101      *
    93      * @return integer
   102      * @return int
    94      */
   103      */
    95     public function getCountObjects()
   104     public function getCountObjects()
    96     {
   105     {
    97         $data= $this->getInfoAccount();
   106         $data= $this->getInfoAccount();
    98         return $data['tot_objects'];
   107         return $data['tot_objects'];
    99     }
   108     }
   100     /**
   109     /**
   101      * Get all the containers
   110      * Get all the containers
   102      *
   111      *
   103      * @param array $options
   112      * @param  array $options
   104      * @return Zend_Service_Rackspace_Files_ContainerList|boolean
   113      * @return Zend_Service_Rackspace_Files_ContainerList|bool
   105      */
   114      */
   106     public function getContainers($options=array())
   115     public function getContainers($options=array())
   107     {
   116     {
   108         $result= $this->httpCall($this->getStorageUrl(),'GET',null,$options);
   117         $result= $this->httpCall($this->getStorageUrl(),'GET',null,$options);
   109         if ($result->isSuccessful()) {
   118         if ($result->isSuccessful()) {
   113     }
   122     }
   114     /**
   123     /**
   115      * Get all the CDN containers
   124      * Get all the CDN containers
   116      *
   125      *
   117      * @param array $options
   126      * @param array $options
   118      * @return array|boolean
   127      * @return array|bool
   119      */
   128      */
   120     public function getCdnContainers($options=array())
   129     public function getCdnContainers($options=array())
   121     {
   130     {
   122         $options['enabled_only']= true;
   131         $options['enabled_only']= true;
   123         $result= $this->httpCall($this->getCdnUrl(),'GET',null,$options);
   132         $result= $this->httpCall($this->getCdnUrl(),'GET',null,$options);
   130      * Get the metadata information of the accounts:
   139      * Get the metadata information of the accounts:
   131      * - total count containers
   140      * - total count containers
   132      * - size in bytes of all the containers
   141      * - size in bytes of all the containers
   133      * - total objects in all the containers
   142      * - total objects in all the containers
   134      * 
   143      * 
   135      * @return array|boolean
   144      * @return array|bool
   136      */
   145      */
   137     public function getInfoAccount()
   146     public function getInfoAccount()
   138     {
   147     {
   139         $result= $this->httpCall($this->getStorageUrl(),'HEAD');
   148         $result= $this->httpCall($this->getStorageUrl(),'HEAD');
   140         if ($result->isSuccessful()) {
   149         if ($result->isSuccessful()) {
   145             );
   154             );
   146             return $output;
   155             return $output;
   147         }
   156         }
   148         return false;
   157         return false;
   149     }
   158     }
       
   159 
   150     /**
   160     /**
   151      * Get all the objects of a container
   161      * Get all the objects of a container
   152      *
   162      *
   153      * @param string $container
   163      * Returns a maximum of 10,000 object names.
   154      * @param array $options
   164      *
   155      * @return  Zend_Service_Rackspace_Files_ObjectList|boolean
   165      * @param  string $container
       
   166      * @param  array  $options
       
   167      * @return bool|Zend_Service_Rackspace_Files_ObjectList
       
   168      * @throws Zend_Service_Rackspace_Exception
   156      */
   169      */
   157     public function getObjects($container,$options=array())
   170     public function getObjects($container,$options=array())
   158     {
   171     {
   159         if (empty($container)) {
   172         if (empty($container)) {
   160             require_once 'Zend/Service/Rackspace/Exception.php';
   173             require_once 'Zend/Service/Rackspace/Exception.php';
   164         if ($result->isSuccessful()) {
   177         if ($result->isSuccessful()) {
   165             return new Zend_Service_Rackspace_Files_ObjectList($this,json_decode($result->getBody(),true),$container);
   178             return new Zend_Service_Rackspace_Files_ObjectList($this,json_decode($result->getBody(),true),$container);
   166         }
   179         }
   167         return false;
   180         return false;
   168     }
   181     }
       
   182 
   169     /**
   183     /**
   170      * Create a container
   184      * Create a container
   171      *
   185      *
   172      * @param string $container
   186      * @param  string $container
   173      * @param array $metadata
   187      * @param  array  $metadata
   174      * @return Zend_Service_Rackspace_Files_Container|boolean
   188      * @return bool|Zend_Service_Rackspace_Files_Container
       
   189      * @throws Zend_Service_Rackspace_Exception
   175      */
   190      */
   176     public function createContainer($container,$metadata=array())
   191     public function createContainer($container,$metadata=array())
   177     {
   192     {
   178         if (empty($container)) {
   193         if (empty($container)) {
   179             require_once 'Zend/Service/Rackspace/Exception.php';
   194             require_once 'Zend/Service/Rackspace/Exception.php';
   201                 break;
   216                 break;
   202         }
   217         }
   203         $this->errorCode= $status;
   218         $this->errorCode= $status;
   204         return false;
   219         return false;
   205     }
   220     }
       
   221 
   206     /**
   222     /**
   207      * Delete a container (only if it's empty)
   223      * Delete a container (only if it's empty)
   208      *
   224      *
   209      * @param sting $container
   225      * @param  string $container
   210      * @return boolean
   226      * @return bool
       
   227      * @throws Zend_Service_Rackspace_Exception
   211      */
   228      */
   212     public function deleteContainer($container)
   229     public function deleteContainer($container)
   213     {
   230     {
   214         if (empty($container)) {
   231         if (empty($container)) {
   215             require_once 'Zend/Service/Rackspace/Exception.php';
   232             require_once 'Zend/Service/Rackspace/Exception.php';
   231                 break;
   248                 break;
   232         }
   249         }
   233         $this->errorCode= $status;
   250         $this->errorCode= $status;
   234         return false;
   251         return false;
   235     }
   252     }
       
   253 
   236     /**
   254     /**
   237      * Get the metadata of a container
   255      * Get the metadata of a container
   238      *
   256      *
   239      * @param string $container
   257      * @param  string $container
   240      * @return array|boolean
   258      * @return array|bool
       
   259      * @throws Zend_Service_Rackspace_Exception
   241      */
   260      */
   242     public function getMetadataContainer($container)
   261     public function getMetadataContainer($container)
   243     {
   262     {
   244         if (empty($container)) {
   263         if (empty($container)) {
   245             require_once 'Zend/Service/Rackspace/Exception.php';
   264             require_once 'Zend/Service/Rackspace/Exception.php';
   277         return false;
   296         return false;
   278     }
   297     }
   279     /**
   298     /**
   280      * Get a container
   299      * Get a container
   281      * 
   300      * 
   282      * @param string $container
   301      * @param  string $container
   283      * @return Container|boolean
   302      * @return Zend_Service_Rackspace_Files_Container|bool
   284      */
   303      */
   285     public function getContainer($container) {
   304     public function getContainer($container) {
   286         $result= $this->getMetadataContainer($container);
   305         $result= $this->getMetadataContainer($container);
   287         if (!empty($result)) {
   306         if (!empty($result)) {
   288             return new Zend_Service_Rackspace_Files_Container($this,$result);
   307             return new Zend_Service_Rackspace_Files_Container($this,$result);
   289         }
   308         }
   290         return false;
   309         return false;
   291     }
   310     }
       
   311 
   292     /**
   312     /**
   293      * Get an object in a container
   313      * Get an object in a container
   294      *
   314      *
   295      * @param string $container
   315      * @param  string $container
   296      * @param string $object
   316      * @param  string $object
   297      * @param array $headers
   317      * @param  array  $headers
   298      * @return Zend_Service_Rackspace_Files_Object|boolean
   318      * @return bool|Zend_Service_Rackspace_Files_Object
       
   319      * @throws Zend_Service_Rackspace_Exception
   299      */
   320      */
   300     public function getObject($container,$object,$headers=array())
   321     public function getObject($container,$object,$headers=array())
   301     {
   322     {
   302         if (empty($container)) {
   323         if (empty($container)) {
   303             require_once 'Zend/Service/Rackspace/Exception.php';
   324             require_once 'Zend/Service/Rackspace/Exception.php';
   329                 break;
   350                 break;
   330         }
   351         }
   331         $this->errorCode= $status;
   352         $this->errorCode= $status;
   332         return false;
   353         return false;
   333     }
   354     }
       
   355 
   334     /**
   356     /**
   335      * Store a file in a container
   357      * Store a file in a container
   336      *
   358      *
   337      * @param string $container
   359      * @param  string $container
   338      * @param string $object
   360      * @param  string $object
   339      * @param string $content
   361      * @param  string $content
   340      * @param array $metadata
   362      * @param  array  $metadata
   341      * @param string $content_type
   363      * @param  string $content_type
   342      *
   364      * @return bool
   343      * @return boolean
   365      * @throws Zend_Service_Rackspace_Exception
   344      */
   366      */
   345     public function storeObject($container,$object,$content,$metadata=array(),$content_type=null) {
   367     public function storeObject($container,$object,$content,$metadata=array(),$content_type=null) {
   346         if (empty($container)) {
   368         if (empty($container)) {
   347             require_once 'Zend/Service/Rackspace/Exception.php';
   369             require_once 'Zend/Service/Rackspace/Exception.php';
   348             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   370             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   381                 break;
   403                 break;
   382         }
   404         }
   383         $this->errorCode= $status;
   405         $this->errorCode= $status;
   384         return false;
   406         return false;
   385     }
   407     }
       
   408 
   386     /**
   409     /**
   387      * Delete an object in a container
   410      * Delete an object in a container
   388      *
   411      *
   389      * @param string $container
   412      * @param  string $container
   390      * @param string $object
   413      * @param  string $object
   391      * @return boolean
   414      * @return bool
       
   415      * @throws Zend_Service_Rackspace_Exception
   392      */
   416      */
   393     public function deleteObject($container,$object) {
   417     public function deleteObject($container,$object) {
   394         if (empty($container)) {
   418         if (empty($container)) {
   395             require_once 'Zend/Service/Rackspace/Exception.php';
   419             require_once 'Zend/Service/Rackspace/Exception.php';
   396             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   420             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   412                 break;
   436                 break;
   413         }
   437         }
   414         $this->errorCode= $status;
   438         $this->errorCode= $status;
   415         return false;
   439         return false;
   416     }
   440     }
       
   441 
   417     /**
   442     /**
   418      * Copy an object from a container to another
   443      * Copy an object from a container to another
   419      *
   444      *
   420      * @param string $container_source
   445      * @param  string $container_source
   421      * @param string $obj_source
   446      * @param  string $obj_source
   422      * @param string $container_dest
   447      * @param  string $container_dest
   423      * @param string $obj_dest
   448      * @param  string $obj_dest
   424      * @param array $metadata
   449      * @param  array  $metadata
   425      * @param string $content_type
   450      * @param  string $content_type
   426      * @return boolean
   451      * @return bool
       
   452      * @throws Zend_Service_Rackspace_Exception
   427      */
   453      */
   428     public function copyObject($container_source,$obj_source,$container_dest,$obj_dest,$metadata=array(),$content_type=null) {
   454     public function copyObject($container_source,$obj_source,$container_dest,$obj_dest,$metadata=array(),$content_type=null) {
   429         if (empty($container_source)) {
   455         if (empty($container_source)) {
   430             require_once 'Zend/Service/Rackspace/Exception.php';
   456             require_once 'Zend/Service/Rackspace/Exception.php';
   431             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_SOURCE_CONTAINER);
   457             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_SOURCE_CONTAINER);
   464                 break;
   490                 break;
   465         }
   491         }
   466         $this->errorCode= $status;
   492         $this->errorCode= $status;
   467         return false;
   493         return false;
   468     }
   494     }
       
   495 
   469     /**
   496     /**
   470      * Get the metadata of an object
   497      * Get the metadata of an object
   471      *
   498      *
   472      * @param string $container
   499      * @param  string $container
   473      * @param string $object
   500      * @param  string $object
   474      * @return array|boolean
   501      * @return array|bool
       
   502      * @throws Zend_Service_Rackspace_Exception
   475      */
   503      */
   476     public function getMetadataObject($container,$object) {
   504     public function getMetadataObject($container,$object) {
   477         if (empty($container)) {
   505         if (empty($container)) {
   478             require_once 'Zend/Service/Rackspace/Exception.php';
   506             require_once 'Zend/Service/Rackspace/Exception.php';
   479             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   507             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   514                 break;
   542                 break;
   515         }
   543         }
   516         $this->errorCode= $status;
   544         $this->errorCode= $status;
   517         return false;
   545         return false;
   518     }
   546     }
       
   547 
   519     /**
   548     /**
   520      * Set the metadata of a object in a container
   549      * Set the metadata of a object in a container
   521      * The old metadata values are replaced with the new one
   550      * The old metadata values are replaced with the new one
   522      * 
   551      *
   523      * @param string $container
   552      * @param  string $container
   524      * @param string $object
   553      * @param  string $object
   525      * @param array $metadata
   554      * @param  array  $metadata
   526      * @return boolean
   555      * @return bool
       
   556      * @throws Zend_Service_Rackspace_Exception
   527      */
   557      */
   528     public function setMetadataObject($container,$object,$metadata)
   558     public function setMetadataObject($container,$object,$metadata)
   529     {
   559     {
   530         if (empty($container)) {
   560         if (empty($container)) {
   531             require_once 'Zend/Service/Rackspace/Exception.php';
   561             require_once 'Zend/Service/Rackspace/Exception.php';
   556                 break;
   586                 break;
   557         }
   587         }
   558         $this->errorCode= $status;
   588         $this->errorCode= $status;
   559         return false;
   589         return false;
   560     }
   590     }
       
   591 
   561     /**
   592     /**
   562      * Enable the CDN for a container
   593      * Enable the CDN for a container
   563      *
   594      *
   564      * @param  string $container
   595      * @param  string $container
   565      * @param  integer $ttl
   596      * @param  int    $ttl
   566      * @return array|boolean
   597      * @return array|bool
       
   598      * @throws Zend_Service_Rackspace_Exception
   567      */
   599      */
   568     public function enableCdnContainer ($container,$ttl=self::CDN_TTL_MIN) {
   600     public function enableCdnContainer ($container,$ttl=self::CDN_TTL_MIN) {
   569         if (empty($container)) {
   601         if (empty($container)) {
   570             require_once 'Zend/Service/Rackspace/Exception.php';
   602             require_once 'Zend/Service/Rackspace/Exception.php';
   571             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   603             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   595                 break;
   627                 break;
   596         }
   628         }
   597         $this->errorCode= $status;
   629         $this->errorCode= $status;
   598         return false;
   630         return false;
   599     }
   631     }
       
   632 
   600     /**
   633     /**
   601      * Update the attribute of a CDN container
   634      * Update the attribute of a CDN container
   602      *
   635      *
   603      * @param  string $container
   636      * @param  string $container
   604      * @param  integer $ttl
   637      * @param  int    $ttl
   605      * @param  boolean $cdn_enabled
   638      * @param  bool   $cdn_enabled
   606      * @param  boolean $log
   639      * @param  bool   $log
   607      * @return boolean
   640      * @return bool
       
   641      * @throws Zend_Service_Rackspace_Exception
   608      */
   642      */
   609     public function updateCdnContainer($container,$ttl=null,$cdn_enabled=null,$log=null)
   643     public function updateCdnContainer($container,$ttl=null,$cdn_enabled=null,$log=null)
   610     {
   644     {
   611         if (empty($container)) {
   645         if (empty($container)) {
   612             require_once 'Zend/Service/Rackspace/Exception.php';
   646             require_once 'Zend/Service/Rackspace/Exception.php';
   653                 break;
   687                 break;
   654         }
   688         }
   655         $this->errorCode= $status;
   689         $this->errorCode= $status;
   656         return false;
   690         return false;
   657     }
   691     }
       
   692 
   658     /**
   693     /**
   659      * Get the information of a Cdn container
   694      * Get the information of a Cdn container
   660      *
   695      *
   661      * @param string $container
   696      * @param  string $container
   662      * @return array|boolean
   697      * @return array|bool
       
   698      * @throws Zend_Service_Rackspace_Exception
   663      */
   699      */
   664     public function getInfoCdnContainer($container) {
   700     public function getInfoCdnContainer($container) {
   665         if (empty($container)) {
   701         if (empty($container)) {
   666             require_once 'Zend/Service/Rackspace/Exception.php';
   702             require_once 'Zend/Service/Rackspace/Exception.php';
   667             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);
   703             throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME_CONTAINER);