File indexing completed on 2025-01-26 05:25:27

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Service_Rackspace
0017  * @subpackage Files
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 
0022 // require_once 'Zend/Service/Rackspace/Files/Object.php';
0023 // require_once 'Zend/Service/Rackspace/Files.php';
0024 
0025 /**
0026  * List of servers retrived from the GoGrid web service
0027  *
0028  * @uses       ArrayAccess
0029  * @uses       Countable
0030  * @uses       Iterator
0031  * @uses       OutOfBoundsException
0032  * @uses       Zend_Service_Rackspace_Files
0033  * @category   Zend
0034  * @package    Zend_Service_Rackspace
0035  * @subpackage Files
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Service_Rackspace_Files_ObjectList implements Countable, Iterator, ArrayAccess
0040 {
0041     /**
0042      * @var array of Zend_Service_Rackspace_Files_Object
0043      */
0044     protected $objects = array();
0045     /**
0046      * @var int Iterator key
0047      */
0048     protected $iteratorKey = 0;
0049     /**
0050      * @var RackspaceFiles
0051      */
0052     protected $service;
0053     /**
0054      * The container name of the object list
0055      * 
0056      * @var string
0057      */
0058     protected $container;
0059     /**
0060      * Construct
0061      *
0062      * @param  array $list
0063      * @return boolean
0064      */
0065     public function __construct($service,$list,$container)
0066     {
0067         if (!($service instanceof Zend_Service_Rackspace_Files)) {
0068             // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0069             throw new Zend_Service_Rackspace_Files_Exception("You must pass a Zend_Service_Rackspace_Files object");
0070         }
0071         if (!is_array($list)) {
0072             // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0073             throw new Zend_Service_Rackspace_Files_Exception("You must pass an array of data objects");
0074         }
0075         if (empty($container)) {
0076             // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0077             throw new Zend_Service_Rackspace_Files_Exception("You must pass the container of the object list");
0078         }
0079         $this->service= $service;
0080         $this->container= $container;
0081         $this->_constructFromArray($list);
0082     }
0083     /**
0084      * Transforms the Array to array of container
0085      *
0086      * @param  array $list
0087      * @return void
0088      */
0089     private function _constructFromArray(array $list)
0090     {
0091         foreach ($list as $obj) {
0092             $obj['container']= $this->container;
0093             $this->_addObject(new Zend_Service_Rackspace_Files_Object($this->service,$obj));
0094         }
0095     }
0096     /**
0097      * Add an object
0098      *
0099      * @param  Zend_Service_Rackspace_Files_Object $obj
0100      * @return Zend_Service_Rackspace_Files_ObjectList
0101      */
0102     protected function _addObject (Zend_Service_Rackspace_Files_Object $obj)
0103     {
0104         $this->objects[] = $obj;
0105         return $this;
0106     }
0107     /**
0108      * Return number of servers
0109      *
0110      * Implement Countable::count()
0111      *
0112      * @return int
0113      */
0114     public function count()
0115     {
0116         return count($this->objects);
0117     }
0118     /**
0119      * Return the current element
0120      *
0121      * Implement Iterator::current()
0122      *
0123      * @return Zend_Service_Rackspace_Files_Object
0124      */
0125     public function current()
0126     {
0127         return $this->objects[$this->iteratorKey];
0128     }
0129     /**
0130      * Return the key of the current element
0131      *
0132      * Implement Iterator::key()
0133      *
0134      * @return int
0135      */
0136     public function key()
0137     {
0138         return $this->iteratorKey;
0139     }
0140     /**
0141      * Move forward to next element
0142      *
0143      * Implement Iterator::next()
0144      *
0145      * @return void
0146      */
0147     public function next()
0148     {
0149         $this->iteratorKey += 1;
0150     }
0151     /**
0152      * Rewind the Iterator to the first element
0153      *
0154      * Implement Iterator::rewind()
0155      *
0156      * @return void
0157      */
0158     public function rewind()
0159     {
0160         $this->iteratorKey = 0;
0161     }
0162     /**
0163      * Check if there is a current element after calls to rewind() or next()
0164      *
0165      * Implement Iterator::valid()
0166      *
0167      * @return bool
0168      */
0169     public function valid()
0170     {
0171         $numItems = $this->count();
0172         if ($numItems > 0 && $this->iteratorKey < $numItems) {
0173             return true;
0174         } else {
0175             return false;
0176         }
0177     }
0178     /**
0179      * Whether the offset exists
0180      *
0181      * Implement ArrayAccess::offsetExists()
0182      *
0183      * @param   int     $offset
0184      * @return  bool
0185      */
0186     public function offsetExists($offset)
0187     {
0188         return ($offset < $this->count());
0189     }
0190     /**
0191      * Return value at given offset
0192      *
0193      * Implement ArrayAccess::offsetGet()
0194      *
0195      * @param   int     $offset
0196      * @throws  Zend_Service_Rackspace_Files_Exception
0197      * @return  Zend_Service_Rackspace_Files_Object
0198      */
0199     public function offsetGet($offset)
0200     {
0201         if ($this->offsetExists($offset)) {
0202             return $this->objects[$offset];
0203         } else {
0204             // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0205             throw new Zend_Service_Rackspace_Files_Exception('Illegal index');
0206         }
0207     }
0208 
0209     /**
0210      * Throws exception because all values are read-only
0211      *
0212      * Implement ArrayAccess::offsetSet()
0213      *
0214      * @param   int     $offset
0215      * @param   string  $value
0216      * @throws  Zend_Service_Rackspace_Files_Exception
0217      */
0218     public function offsetSet($offset, $value)
0219     {
0220         // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0221         throw new Zend_Service_Rackspace_Files_Exception('You are trying to set read-only property');
0222     }
0223 
0224     /**
0225      * Throws exception because all values are read-only
0226      *
0227      * Implement ArrayAccess::offsetUnset()
0228      *
0229      * @param   int     $offset
0230      * @throws  Zend_Service_Rackspace_Files_Exception
0231      */
0232     public function offsetUnset($offset)
0233     {
0234         // require_once 'Zend/Service/Rackspace/Files/Exception.php';
0235         throw new Zend_Service_Rackspace_Files_Exception('You are trying to unset read-only property');
0236     }
0237 }