web/lib/Zend/Service/Rackspace/Files/Object.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_Rackspace
    16  * @package    Zend_Service_Rackspace
    17  * @subpackage Files
    17  * @subpackage Files
    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/Files.php';
    22 require_once 'Zend/Service/Rackspace/Files.php';
    23 
    23 
    27      * The service that has created the object
    27      * The service that has created the object
    28      *
    28      *
    29      * @var Zend_Service_Rackspace_Files
    29      * @var Zend_Service_Rackspace_Files
    30      */
    30      */
    31     protected $service;
    31     protected $service;
       
    32 
    32     /**
    33     /**
    33      * Name of the object
    34      * Name of the object
    34      *
    35      *
    35      * @var string
    36      * @var string
    36      */
    37      */
    37     protected $name;
    38     protected $name;
       
    39 
    38     /**
    40     /**
    39      * MD5 value of the object's content
    41      * MD5 value of the object's content
    40      *
    42      *
    41      * @var string
    43      * @var string
    42      */
    44      */
    43     protected $hash;
    45     protected $hash;
       
    46 
    44     /**
    47     /**
    45      * Size in bytes of the object's content
    48      * Size in bytes of the object's content
    46      *
    49      *
    47      * @var integer
    50      * @var integer
    48      */
    51      */
    49     protected $size;
    52     protected $size;
       
    53 
    50     /**
    54     /**
    51      * Content type of the object's content
    55      * Content type of the object's content
    52      *
    56      *
    53      * @var string
    57      * @var string
    54      */
    58      */
    55     protected $contentType;
    59     protected $contentType;
       
    60 
    56     /**
    61     /**
    57      * Date of the last modified of the object
    62      * Date of the last modified of the object
    58      *
    63      *
    59      * @var string
    64      * @var string
    60      */
    65      */
    61     protected $lastModified;
    66     protected $lastModified;
       
    67 
    62     /**
    68     /**
    63      * Object content
    69      * Object content
    64      *
    70      *
    65      * @var string
    71      * @var string
    66      */
    72      */
    67     protected $content;
    73     protected $content;
       
    74 
    68     /**
    75     /**
    69      * Name of the container where the object is stored
    76      * Name of the container where the object is stored
    70      *
    77      *
    71      * @var string
    78      * @var string
    72      */
    79      */
    73     protected $container;
    80     protected $container;
       
    81 
    74     /**
    82     /**
    75      * Constructor
    83      * Constructor
    76      * 
    84      *
    77      * You must pass the Zend_Service_Rackspace_Files object of the caller and an associative
    85      * You must pass the Zend_Service_Rackspace_Files object of the caller and an associative
    78      * array with the keys "name", "container", "hash", "bytes", "content_type",
    86      * array with the keys "name", "container", "hash", "bytes", "content_type",
    79      * "last_modified", "file" where:
    87      * "last_modified", "file" where:
    80      * name= name of the object
    88      * name= name of the object
    81      * container= name of the container where the object is stored
    89      * container= name of the container where the object is stored
    82      * hash= the MD5 of the object's content
    90      * hash= the MD5 of the object's content
    83      * bytes= size in bytes of the object's content
    91      * bytes= size in bytes of the object's content
    84      * content_type= content type of the object's content
    92      * content_type= content type of the object's content
    85      * last_modified= date of the last modified of the object
    93      * last_modified= date of the last modified of the object
    86      * content= content of the object
    94      * content= content of the object
    87      * 
    95      *
    88      * @param Zend_Service_Rackspace_Files $service
    96      * @param Zend_Service_Rackspace_Files $service
    89      * @param array $data 
    97      * @param array                        $data
    90      */
    98      * @throws Zend_Service_Rackspace_Files_Exception
    91     public function __construct($service,$data)
    99      */
       
   100     public function __construct($service, $data)
    92     {
   101     {
    93         if (!($service instanceof Zend_Service_Rackspace_Files) || !is_array($data)) {
   102         if (!($service instanceof Zend_Service_Rackspace_Files) || !is_array($data)) {
    94             require_once 'Zend/Service/Rackspace/Files/Exception.php';
   103             require_once 'Zend/Service/Rackspace/Files/Exception.php';
    95             throw new Zend_Service_Rackspace_Files_Exception("You must pass a RackspaceFiles and an array");
   104             throw new Zend_Service_Rackspace_Files_Exception(
    96         }
   105                 'You must pass a RackspaceFiles and an array'
    97         if (!array_key_exists('name', $data)) {
   106             );
    98             require_once 'Zend/Service/Rackspace/Files/Exception.php';
       
    99             throw new Zend_Service_Rackspace_Files_Exception("You must pass the name of the object in the array (name)");
       
   100         }
   107         }
   101         if (!array_key_exists('container', $data)) {
   108         if (!array_key_exists('container', $data)) {
   102             require_once 'Zend/Service/Rackspace/Files/Exception.php';
   109             require_once 'Zend/Service/Rackspace/Files/Exception.php';
   103             throw new Zend_Service_Rackspace_Files_Exception("You must pass the container of the object in the array (container)");
   110             throw new Zend_Service_Rackspace_Files_Exception(
   104         }
   111                 'You must pass the container of the object in the array (container)'
   105         if (!array_key_exists('hash', $data)) {
   112             );
       
   113         }
       
   114         if (array_key_exists('name', $data)) {
       
   115             if (!array_key_exists('hash', $data)) {
       
   116                 require_once 'Zend/Service/Rackspace/Files/Exception.php';
       
   117                 throw new Zend_Service_Rackspace_Files_Exception(
       
   118                     'You must pass the hash of the object in the array (hash)'
       
   119                 );
       
   120             }
       
   121             if (!array_key_exists('bytes', $data)) {
       
   122                 require_once 'Zend/Service/Rackspace/Files/Exception.php';
       
   123                 throw new Zend_Service_Rackspace_Files_Exception(
       
   124                     'You must pass the byte size of the object in the array (bytes)'
       
   125                 );
       
   126             }
       
   127             if (!array_key_exists('content_type', $data)) {
       
   128                 require_once 'Zend/Service/Rackspace/Files/Exception.php';
       
   129                 throw new Zend_Service_Rackspace_Files_Exception(
       
   130                     'You must pass the content type of the object in the array (content_type)'
       
   131                 );
       
   132             }
       
   133             if (!array_key_exists('last_modified', $data)) {
       
   134                 require_once 'Zend/Service/Rackspace/Files/Exception.php';
       
   135                 throw new Zend_Service_Rackspace_Files_Exception(
       
   136                     'You must pass the last modified data of the object in the array (last_modified)'
       
   137                 );
       
   138             }
       
   139 
       
   140             $this->name         = $data['name'];
       
   141             $this->hash         = $data['hash'];
       
   142             $this->size         = $data['bytes'];
       
   143             $this->contentType  = $data['content_type'];
       
   144             $this->lastModified = $data['last_modified'];
       
   145 
       
   146             if (!empty($data['content'])) {
       
   147                 $this->content = $data['content'];
       
   148             }
       
   149         } elseif (array_key_exists('subdir', $data)) {
       
   150             $this->name = $data['subdir'];
       
   151         } else {
   106             require_once 'Zend/Service/Rackspace/Files/Exception.php';
   152             require_once 'Zend/Service/Rackspace/Files/Exception.php';
   107             throw new Zend_Service_Rackspace_Files_Exception("You must pass the hash of the object in the array (hash)");
   153             throw new Zend_Service_Rackspace_Files_Exception(
   108         }
   154                 'You must pass the name of the object in the array (name)'
   109         if (!array_key_exists('bytes', $data)) {
   155             );
   110             require_once 'Zend/Service/Rackspace/Files/Exception.php';
   156         }
   111             throw new Zend_Service_Rackspace_Files_Exception("You must pass the byte size of the object in the array (bytes)");
   157 
   112         }
   158         $this->container = $data['container'];
   113         if (!array_key_exists('content_type', $data)) {
   159         $this->service   = $service;
   114             require_once 'Zend/Service/Rackspace/Files/Exception.php';
   160     }
   115             throw new Zend_Service_Rackspace_Files_Exception("You must pass the content type of the object in the array (content_type)");
   161 
   116         }
       
   117         if (!array_key_exists('last_modified', $data)) {
       
   118             require_once 'Zend/Service/Rackspace/Files/Exception.php';
       
   119             throw new Zend_Service_Rackspace_Files_Exception("You must pass the last modified data of the object in the array (last_modified)");
       
   120         }
       
   121         $this->name= $data['name'];
       
   122         $this->container= $data['container'];
       
   123         $this->hash= $data['hash'];
       
   124         $this->size= $data['bytes'];
       
   125         $this->contentType= $data['content_type'];
       
   126         $this->lastModified= $data['last_modified'];
       
   127         if (!empty($data['content'])) {
       
   128             $this->content= $data['content'];
       
   129         }
       
   130         $this->service= $service;
       
   131     }
       
   132     /**
   162     /**
   133      * Get name
   163      * Get name
   134      *
   164      *
   135      * @return string
   165      * @return string
   136      */
   166      */
   137     public function getName() 
   167     public function getName() 
   138     {
   168     {
   139         return $this->name;
   169         return $this->name;
   140     }
   170     }
       
   171 
   141     /**
   172     /**
   142      * Get the name of the container
   173      * Get the name of the container
   143      *
   174      *
   144      * @return string
   175      * @return string
   145      */
   176      */
   146     public function getContainer() 
   177     public function getContainer() 
   147     {
   178     {
   148         return $this->container;
   179         return $this->container;
   149     }
   180     }
       
   181 
   150     /**
   182     /**
   151      * Get the MD5 of the object's content
   183      * Get the MD5 of the object's content
   152      *
   184      *
   153      * @return string|boolean
   185      * @return string|boolean
   154      */
   186      */
   155     public function getHash() 
   187     public function getHash() 
   156     {
   188     {
   157         return $this->hash;
   189         return $this->hash;
   158     }
   190     }
       
   191 
   159     /**
   192     /**
   160      * Get the size (in bytes) of the object's content
   193      * Get the size (in bytes) of the object's content
   161      *
   194      *
   162      * @return integer|boolean
   195      * @return integer|boolean
   163      */
   196      */
   164     public function getSize() 
   197     public function getSize() 
   165     {
   198     {
   166         return $this->size;
   199         return $this->size;
   167     }
   200     }
       
   201 
   168     /**
   202     /**
   169      * Get the content type of the object's content
   203      * Get the content type of the object's content
   170      *
   204      *
   171      * @return string
   205      * @return string
   172      */
   206      */
   173     public function getContentType() 
   207     public function getContentType() 
   174     {
   208     {
   175         return $this->contentType;
   209         return $this->contentType;
   176     }
   210     }
       
   211 
   177     /**
   212     /**
   178      * Get the data of the last modified of the object
   213      * Get the data of the last modified of the object
   179      *
   214      *
   180      * @return string
   215      * @return string
   181      */
   216      */
   182     public function getLastModified() 
   217     public function getLastModified() 
   183     {
   218     {
   184         return $this->lastModified;
   219         return $this->lastModified;
   185     }
   220     }
       
   221 
   186     /**
   222     /**
   187      * Get the content of the object
   223      * Get the content of the object
   188      *
   224      *
   189      * @return string
   225      * @return string
   190      */
   226      */
   191     public function getContent() 
   227     public function getContent() 
   192     {
   228     {
   193         return $this->content;
   229         return $this->content;
   194     }
   230     }
       
   231 
   195     /**
   232     /**
   196      * Get the metadata of the object
   233      * Get the metadata of the object
   197      * If you don't pass the $key it returns the entire array of metadata value
   234      * If you don't pass the $key it returns the entire array of metadata value
   198      *
   235      *
   199      * @param  string $key
   236      * @param  string $key
   210                 return $result['metadata'][$key];
   247                 return $result['metadata'][$key];
   211             }
   248             }
   212         }
   249         }
   213         return false;
   250         return false;
   214     }
   251     }
       
   252 
   215     /**
   253     /**
   216      * Set the metadata value
   254      * Set the metadata value
   217      * The old metadata values are replaced with the new one
   255      * The old metadata values are replaced with the new one
   218      * 
   256      * 
   219      * @param array $metadata
   257      * @param array $metadata
   221      */
   259      */
   222     public function setMetadata($metadata) 
   260     public function setMetadata($metadata) 
   223     {
   261     {
   224         return $this->service->setMetadataObject($this->container,$this->name,$metadata);
   262         return $this->service->setMetadataObject($this->container,$this->name,$metadata);
   225     }
   263     }
       
   264 
   226     /**
   265     /**
   227      * Copy the object to another container
   266      * Copy the object to another container
   228      * You can add metadata information to the destination object, change the
   267      * You can add metadata information to the destination object, change the
   229      * content_type and the name of the object
   268      * content_type and the name of the object
   230      *
   269      *
   236      */
   275      */
   237     public function copyTo($container_dest,$name_dest,$metadata=array(),$content_type=null) 
   276     public function copyTo($container_dest,$name_dest,$metadata=array(),$content_type=null) 
   238     {
   277     {
   239         return $this->service->copyObject($this->container,$this->name,$container_dest,$name_dest,$metadata,$content_type);
   278         return $this->service->copyObject($this->container,$this->name,$container_dest,$name_dest,$metadata,$content_type);
   240     }
   279     }
       
   280 
   241     /**
   281     /**
   242      * Get the CDN URL of the object
   282      * Get the CDN URL of the object
   243      *
   283      *
   244      * @return string
   284      * @return string
   245      */
   285      */
   251                 return $result['cdn_uri'].'/'.$this->name;
   291                 return $result['cdn_uri'].'/'.$this->name;
   252             }
   292             }
   253         }
   293         }
   254         return false;
   294         return false;
   255     }
   295     }
       
   296 
   256     /**
   297     /**
   257      * Get the CDN SSL URL of the object
   298      * Get the CDN SSL URL of the object
   258      *
   299      *
   259      * @return string
   300      * @return string
   260      */
   301      */