File indexing completed on 2024-12-29 05:28:02
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_SharedIpGroup 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 const ERROR_PARAM_NO_SERVERS = 'The servers parameter must be an array of Ids'; 0031 /** 0032 * Name of the shared IP group 0033 * 0034 * @var string 0035 */ 0036 protected $name; 0037 /** 0038 * Id of the shared IP group 0039 * 0040 * @var string 0041 */ 0042 protected $id; 0043 /** 0044 * Array of servers of the shared IP group 0045 * 0046 * @var array 0047 */ 0048 protected $serversId = array(); 0049 /** 0050 * The service that has created the image object 0051 * 0052 * @var Zend_Service_Rackspace_Servers 0053 */ 0054 protected $service; 0055 /** 0056 * Construct 0057 * 0058 * @param Zend_Service_Rackspace_Servers $service 0059 * @param array $data 0060 * @return void 0061 */ 0062 public function __construct($service, $data) 0063 { 0064 if (!($service instanceof Zend_Service_Rackspace_Servers) || !is_array($data)) { 0065 // require_once 'Zend/Service/Rackspace/Servers/Exception.php'; 0066 throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_CONSTRUCT); 0067 } 0068 if (!array_key_exists('name', $data)) { 0069 // require_once 'Zend/Service/Rackspace/Servers/Exception.php'; 0070 throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_NO_NAME); 0071 } 0072 if (!array_key_exists('id', $data)) { 0073 // require_once 'Zend/Service/Rackspace/Servers/Exception.php'; 0074 throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_NO_ID); 0075 } 0076 if (isset($data['servers']) && !is_array($data['servers'])) { 0077 // require_once 'Zend/Service/Rackspace/Servers/Exception.php'; 0078 throw new Zend_Service_Rackspace_Servers_Exception(self::ERROR_PARAM_NO_SERVERS); 0079 } 0080 $this->service= $service; 0081 $this->name = $data['name']; 0082 $this->id = $data['id']; 0083 if (isset($data['servers'])) { 0084 $this->serversId= $data['servers']; 0085 } 0086 } 0087 /** 0088 * Get the name of the shared IP group 0089 * 0090 * @return string 0091 */ 0092 public function getName() 0093 { 0094 return $this->name; 0095 } 0096 /** 0097 * Get the id of the shared IP group 0098 * 0099 * @return string 0100 */ 0101 public function getId() 0102 { 0103 return $this->id; 0104 } 0105 /** 0106 * Get the server's array of the shared IP group 0107 * 0108 * @return string 0109 */ 0110 public function getServersId() 0111 { 0112 if (empty($this->serversId)) { 0113 $info= $this->service->getSharedIpGroup($this->id); 0114 if (($info!==false)) { 0115 $info= $info->toArray(); 0116 if (isset($info['servers'])) { 0117 $this->serversId= $info['servers']; 0118 } 0119 } 0120 } 0121 return $this->serversId; 0122 } 0123 /** 0124 * Get the server 0125 * 0126 * @param integer $id 0127 * @return Zend_Service_Rackspace_Servers_Server|boolean 0128 */ 0129 public function getServer($id) 0130 { 0131 if (empty($this->serversId)) { 0132 $this->getServersId(); 0133 } 0134 if (in_array($id,$this->serversId)) { 0135 return $this->service->getServer($id); 0136 } 0137 return false; 0138 } 0139 /** 0140 * Create a server in the shared Ip Group 0141 * 0142 * @param array $data 0143 * @param array $metadata 0144 * @param array $files 0145 * @return Zend_Service_Rackspace_Servers_Server|boolean 0146 */ 0147 public function createServer(array $data, $metadata=array(),$files=array()) 0148 { 0149 $data['sharedIpGroupId']= (integer) $this->id; 0150 return $this->service->createServer($data,$metadata,$files); 0151 } 0152 /** 0153 * To Array 0154 * 0155 * @return array 0156 */ 0157 public function toArray() 0158 { 0159 return array ( 0160 'name' => $this->name, 0161 'id' => $this->id, 0162 'servers' => $this->serversId 0163 ); 0164 } 0165 }