File indexing completed on 2025-01-26 05:24:52
0001 <?php 0002 /** 0003 * @category Zend 0004 * @package Zend_Cloud 0005 * @subpackage Infrastructure 0006 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0007 * @license http://framework.zend.com/license/new-bsd New BSD License 0008 */ 0009 0010 0011 // require_once 'Zend/Cloud/Infrastructure/Image.php'; 0012 0013 /** 0014 * List of images 0015 * 0016 * @package Zend_Cloud 0017 * @subpackage Infrastructure 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 */ 0021 class Zend_Cloud_Infrastructure_ImageList implements Countable, Iterator, ArrayAccess 0022 { 0023 /** 0024 * @var array Array of Zend_Cloud_Infrastructure_Image 0025 */ 0026 protected $images = array(); 0027 0028 /** 0029 * @var int Iterator key 0030 */ 0031 protected $iteratorKey = 0; 0032 0033 /** 0034 * The Image adapter (if exists) 0035 * 0036 * @var object 0037 */ 0038 protected $adapter; 0039 0040 /** 0041 * Constructor 0042 * 0043 * @param array $list 0044 * @param null|object $adapter 0045 * @return boolean 0046 */ 0047 public function __construct($images, $adapter = null) 0048 { 0049 if (empty($images) || !is_array($images)) { 0050 // require_once 'Zend/Cloud/Infrastructure/Exception.php'; 0051 throw new Zend_Cloud_Infrastructure_Exception(__CLASS__ . ' expects an array of images'); 0052 } 0053 0054 $this->adapter = $adapter; 0055 $this->constructFromArray($images); 0056 } 0057 0058 /** 0059 * Transforms the Array to array of Instances 0060 * 0061 * @param array $list 0062 * @return void 0063 */ 0064 protected function constructFromArray(array $list) 0065 { 0066 foreach ($list as $image) { 0067 $this->addImage(new Zend_Cloud_Infrastructure_Image($image, $this->adapter)); 0068 } 0069 } 0070 0071 /** 0072 * Add an image 0073 * 0074 * @param Image 0075 * @return ImageList 0076 */ 0077 protected function addImage(Zend_Cloud_Infrastructure_Image $image) 0078 { 0079 $this->images[] = $image; 0080 return $this; 0081 } 0082 0083 /** 0084 * Return number of images 0085 * 0086 * Implement Countable::count() 0087 * 0088 * @return int 0089 */ 0090 public function count() 0091 { 0092 return count($this->images); 0093 } 0094 0095 /** 0096 * Return the current element 0097 * 0098 * Implement Iterator::current() 0099 * 0100 * @return Image 0101 */ 0102 public function current() 0103 { 0104 return $this->images[$this->iteratorKey]; 0105 } 0106 0107 /** 0108 * Return the key of the current element 0109 * 0110 * Implement Iterator::key() 0111 * 0112 * @return int 0113 */ 0114 public function key() 0115 { 0116 return $this->iteratorKey; 0117 } 0118 0119 /** 0120 * Move forward to next element 0121 * 0122 * Implement Iterator::next() 0123 * 0124 * @return void 0125 */ 0126 public function next() 0127 { 0128 $this->iteratorKey++; 0129 } 0130 0131 /** 0132 * Rewind the Iterator to the first element 0133 * 0134 * Implement Iterator::rewind() 0135 * 0136 * @return void 0137 */ 0138 public function rewind() 0139 { 0140 $this->iteratorKey = 0; 0141 } 0142 0143 /** 0144 * Check if there is a current element after calls to rewind() or next() 0145 * 0146 * Implement Iterator::valid() 0147 * 0148 * @return bool 0149 */ 0150 public function valid() 0151 { 0152 $numItems = $this->count(); 0153 if ($numItems > 0 && $this->iteratorKey < $numItems) { 0154 return true; 0155 } 0156 return false; 0157 } 0158 0159 /** 0160 * Whether the offset exists 0161 * 0162 * Implement ArrayAccess::offsetExists() 0163 * 0164 * @param int $offset 0165 * @return bool 0166 */ 0167 public function offsetExists($offset) 0168 { 0169 return ($offset < $this->count()); 0170 } 0171 0172 /** 0173 * Return value at given offset 0174 * 0175 * Implement ArrayAccess::offsetGet() 0176 * 0177 * @param int $offset 0178 * @throws Zend_Cloud_Infrastructure_Exception 0179 * @return Image 0180 */ 0181 public function offsetGet($offset) 0182 { 0183 if (!$this->offsetExists($offset)) { 0184 // require_once 'Zend/Cloud/Infrastructure/Exception.php'; 0185 throw new Zend_Cloud_Infrastructure_Exception('Illegal index'); 0186 } 0187 return $this->images[$offset]; 0188 } 0189 0190 /** 0191 * Throws exception because all values are read-only 0192 * 0193 * Implement ArrayAccess::offsetSet() 0194 * 0195 * @param int $offset 0196 * @param string $value 0197 * @throws Zend_Cloud_Infrastructure_Exception 0198 */ 0199 public function offsetSet($offset, $value) 0200 { 0201 // require_once 'Zend/Cloud/Infrastructure/Exception.php'; 0202 throw new Zend_Cloud_Infrastructure_Exception('You are trying to set read-only property'); 0203 } 0204 0205 /** 0206 * Throws exception because all values are read-only 0207 * 0208 * Implement ArrayAccess::offsetUnset() 0209 * 0210 * @param int $offset 0211 * @throws Zend_Cloud_Infrastructure_Exception 0212 */ 0213 public function offsetUnset($offset) 0214 { 0215 // require_once 'Zend/Cloud/Infrastructure/Exception.php'; 0216 throw new Zend_Cloud_Infrastructure_Exception('You are trying to unset read-only property'); 0217 } 0218 }