File indexing completed on 2025-01-26 05:25:27
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Service_Rackspace 0018 * @subpackage Servers 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 */ 0022 0023 // require_once 'Zend/Service/Rackspace/Servers.php'; 0024 0025 class Zend_Service_Rackspace_Servers_Image 0026 { 0027 const ERROR_PARAM_CONSTRUCT = 'You must pass a Zend_Service_Rackspace_Servers object and an array'; 0028 const ERROR_PARAM_NO_NAME = 'You must pass the image\'s name in the array (name)'; 0029 const ERROR_PARAM_NO_ID = 'You must pass the image\'s id in the array (id)'; 0030 /** 0031 * Name of the image 0032 * 0033 * @var string 0034 */ 0035 protected $name; 0036 /** 0037 * Id of the image 0038 * 0039 * @var string 0040 */ 0041 protected $id; 0042 /** 0043 * Server Id of the image 0044 * 0045 * @var string 0046 */ 0047 protected $serverId; 0048 /** 0049 * Updated data 0050 * 0051 * @var string 0052 */ 0053 protected $updated; 0054 /** 0055 * Created data 0056 * 0057 * @var string 0058 */ 0059 protected $created; 0060 /** 0061 * Status 0062 * 0063 * @var string 0064 */ 0065 protected $status; 0066 /** 0067 * Status progress 0068 * 0069 * @var integer 0070 */ 0071 protected $progress; 0072 /** 0073 * The service that has created the image object 0074 * 0075 * @var Zend_Service_Rackspace_Servers 0076 */ 0077 protected $service; 0078 /** 0079 * Construct 0080 * 0081 * @param array $data 0082 * @return void 0083 */ 0084 public function __construct($service, $data) 0085 { 0086 if (!($service instanceof Zend_Service_Rackspace_Servers) || !is_array($data)) { 0087 // require_once 'Zend/Service/Rackspace/Servers/Exception.php'; 0088 throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_CONSTRUCT); 0089 } 0090 if (!array_key_exists('name', $data)) { 0091 // require_once 'Zend/Service/Rackspace/Servers/Exception.php'; 0092 throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_NO_NAME); 0093 } 0094 if (!array_key_exists('id', $data)) { 0095 // require_once 'Zend/Service/Rackspace/Servers/Exception.php'; 0096 throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_NO_ID); 0097 } 0098 $this->service= $service; 0099 $this->name = $data['name']; 0100 $this->id = $data['id']; 0101 if (isset($data['serverId'])) { 0102 $this->serverId= $data['serverId']; 0103 } 0104 if (isset($data['updated'])) { 0105 $this->updated= $data['updated']; 0106 } 0107 if (isset($data['created'])) { 0108 $this->created= $data['created']; 0109 } 0110 if (isset($data['status'])) { 0111 $this->status= $data['status']; 0112 } 0113 if (isset($data['progress'])) { 0114 $this->progress= $data['progress']; 0115 } 0116 } 0117 /** 0118 * Get the name of the image 0119 * 0120 * @return string 0121 */ 0122 public function getName() 0123 { 0124 return $this->name; 0125 } 0126 /** 0127 * Get the image's id 0128 * 0129 * @return string 0130 */ 0131 public function getId() 0132 { 0133 return $this->id; 0134 } 0135 /** 0136 * Get the server's id of the image 0137 * 0138 * @return string 0139 */ 0140 public function getServerId() 0141 { 0142 return $this->serverId; 0143 } 0144 /** 0145 * Get the updated data 0146 * 0147 * @return string 0148 */ 0149 public function getUpdated() 0150 { 0151 return $this->updated; 0152 } 0153 /** 0154 * Get the created data 0155 * 0156 * @return string 0157 */ 0158 public function getCreated() 0159 { 0160 return $this->created; 0161 } 0162 /** 0163 * Get the image's status 0164 * 0165 * @return string|boolean 0166 */ 0167 public function getStatus() 0168 { 0169 $data= $this->service->getImage($this->id); 0170 if ($data!==false) { 0171 $data= $data->toArray(); 0172 $this->status= $data['status']; 0173 return $this->status; 0174 } 0175 return false; 0176 } 0177 /** 0178 * Get the progress's status 0179 * 0180 * @return integer|boolean 0181 */ 0182 public function getProgress() 0183 { 0184 $data= $this->service->getImage($this->id); 0185 if ($data!==false) { 0186 $data= $data->toArray(); 0187 $this->progress= $data['progress']; 0188 return $this->progress; 0189 } 0190 return false; 0191 } 0192 /** 0193 * To Array 0194 * 0195 * @return array 0196 */ 0197 public function toArray() 0198 { 0199 return array ( 0200 'name' => $this->name, 0201 'id' => $this->id, 0202 'serverId' => $this->serverId, 0203 'updated' => $this->updated, 0204 'created' => $this->created, 0205 'status' => $this->status, 0206 'progress' => $this->progress 0207 ); 0208 } 0209 }